473,804 Members | 3,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access bug? Not displaying query results... kind of.

29 New Member
Hey all,

This may be the dumbest thing I've ever seen. I'm creating a queryDef in VBA for access. Here's a sample of the query it creates:

Expand|Select|Wrap|Line Numbers
  1. SELECT tblEquipment.equipmentID, tblSample.sampleDate, tblSampleResults.Chromium, IIf([x]=True,'X',(IIf([u]=True,'U',' '))) AS Critical
  2.  
  3. FROM (((tblEquipment 
  4. INNER JOIN tblCompartment ON tblEquipment.[equipmentID] = tblCompartment.[equipmentID]) 
  5. INNER JOIN tblSample ON tblCompartment.[compartmentAutoID] = tblSample.[compartmentSpecific]) 
  6. INNER JOIN tblSampleResults ON tblSample.[sampleNumber] = tblSampleResults.[sampleCode]) 
  7. LEFT JOIN tblSignificant ON tblSampleResults.sampleID = tblSignificant.sampleCode
  8.  
  9. WHERE (((tblEquipment.equipmentID)=31757 Or (tblEquipment.equipmentID)=31774 Or (tblEquipment.equipmentID)=39858 Or (tblEquipment.equipmentID)=39879 Or (tblEquipment.equipmentID)=52718 Or (tblEquipment.equipmentID)=52832 Or (tblEquipment.equipmentID)=52841 Or (tblEquipment.equipmentID)=52842 Or (tblEquipment.equipmentID)=52843 Or (tblEquipment.equipmentID)=81076 Or (tblEquipment.equipmentID)=89801 Or (tblEquipment.equipmentID)=102055 Or (tblEquipment.equipmentID)=102850 Or (tblEquipment.equipmentID)=109801 Or (tblEquipment.equipmentID)=109898 Or (tblEquipment.equipmentID)=109919 Or (tblEquipment.equipmentID)=109920 Or (tblEquipment.equipmentID)=111722 Or (tblEquipment.equipmentID)=121301 Or (tblEquipment.equipmentID)=190860 Or (tblEquipment.equipmentID)=190933 Or (tblEquipment.equipmentID)=239817 Or (tblEquipment.equipmentID)=372013 Or (tblEquipment.equipmentID)=372053 Or (tblEquipment.equipmentID)=372227 Or (tblEquipment.equipmentID)=379908) 
  10. AND ((tblSample.sampleDate)>=#3/3/2007# And (tblSample.sampleDate)<=#12/11/2009#) AND ((tblCompartment.compartmentCode)=1) AND ((tblSignificant.field) Is Null Or (tblSignificant.field)='Chromium'))
  11. ORDER BY tblEquipment.equipmentID;
Now here's the kicker, if I open the query it doesn't show any results. BUT (and this is wild) if I change anything it will display. Say I enter the query designer and show, and then rehide something, change the one column to "Critica" instead of "Critical", ANYTHING - It will display the proper results!

I have no idea why this could happen. it happened once I put in the conditional above that reads " ((tblSignifican t.field) Is Null Or (tblSignificant .field)='Chromi um'))", but I need it there. Until I put that in everything was working fine. I thought that maybe "field" was a reserved word so I just tried changing it to "fieldName" and it still doesn't work.

Help! :(
Dec 12 '09 #1
4 1723
CoreyReynolds
29 New Member
Here's my no good code btw:

(won't let me edit original reply or add code tags to the below, not sure why sorry.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnTrend_Click()
  2.  
  3. 'Create Query
  4. Dim query As String
  5. Dim db As Database
  6. Dim rs As Recordset
  7. Set db = CurrentDb
  8. Dim mySql As String
  9. Dim valSelect As Variant
  10. Dim strValue As String
  11. Dim firstEquip As String
  12. firstEquip = True
  13. Dim ValSelectE As Variant
  14. Dim strValueE As String
  15. Dim valSel As String
  16.  
  17.  
  18.  
  19.  
  20. Dim chartLabel As String
  21. chartLabel = "Sample Result Trending - " & Me.lstCompChoice.Column(1) & " : " & Me.equipmentID.Value & " [" & Me.equipmentDescription.Value & "]"
  22. 'Ensure proper information is selected
  23. If Me.lstCompChoice.ItemsSelected.Count > 0 And Me.lstTrendChoice.ItemsSelected.Count > 0 And Me.txtDateStart <> "" And Me.txtDateEnd <> "" Then
  24.  
  25. 'Create begining of query
  26. mySql = "SELECT tblEquipment.equipmentID, tblSample.sampleDate, "
  27.  
  28.  
  29.     'This section just adds the particular component to the SQL String
  30.     For Each valSelect In Me.lstTrendChoice.ItemsSelected
  31.         If lstTrendChoice.Selected(valSelect) Then
  32.             mySql = mySql & " tblSampleResults." & Me.lstTrendChoice.ItemData(valSelect) & ","
  33.             valSel = (Me.lstTrendChoice.ItemData(valSelect))
  34.  
  35.         End If
  36.     Next valSelect
  37. mySql = mySql & " IIf([x]=True,'X',(IIf([u]=True,'U',' '))) AS Critical,"
  38. 'Clip last useless comma
  39. mySql = Left(mySql, Len(mySql) - 1)
  40.  
  41. 'Create query to turn into chart
  42. mySql = mySql & " FROM (((tblEquipment INNER JOIN tblCompartment ON tblEquipment.[equipmentID] = tblCompartment.[equipmentID])" & _
  43. " INNER JOIN tblSample ON tblCompartment.[compartmentAutoID] = tblSample.[compartmentSpecific]) INNER JOIN" & _
  44. " tblSampleResults ON tblSample.[sampleNumber] = tblSampleResults.[sampleCode] " & _
  45. ") Left JOIN tblSignificant ON tblSampleResults.sampleID = tblSignificant.sampleCode" & _
  46. " WHERE tblCompartment.compartmentCode=" & Me.lstCompChoice.Value
  47.  
  48. 'Insert conditional of equipment loop
  49. For Each valSelect In Me.Combo7.ItemsSelected
  50.     If Me.Combo7.Selected(valSelect) Then
  51.         If firstEquip Then
  52.             mySql = mySql & " And (tblEquipment.equipmentID=" & Me.Combo7.ItemData(valSelect)
  53.             firstEquip = False
  54.         Else
  55.             mySql = mySql & " OR tblEquipment.equipmentID=" & Me.Combo7.ItemData(valSelect)
  56.         End If
  57.     End If
  58. Next valSelect
  59.  
  60. mySql = mySql & ") AND (tblSample.sampleDate >= #" & Me.txtDateStart.Value & "# and tblSample.sampleDate <= #" & Me.txtDateEnd.Value & "#)"
  61. mySql = mySql & "AND (tblSignificant.field ='" & Replace(Me.lstTrendChoice.Value, " ", "") & "' OR tblSignificant.field = null)" & " ORDER BY tblEquipment.equipmentID ASC;"
  62.  
  63. 'delete if old temp query exists
  64. Dim qdf As Variant
  65. For Each qdf In db.QueryDefs
  66. If qdf.Name = "qryTemp" Then
  67. db.QueryDefs.Delete "qryTemp"
  68. Exit For
  69. End If
  70. Next
  71.  
  72.  
  73. 'create new query
  74.  
  75. db.CreateQueryDef "qryTemp", mySql
  76.  
  77. CreateDAOChartM "qryTemp", valSel
  78.  
  79.  
  80.  
  81.  
  82. End If
  83.  
  84. 'Pass Query into chart creation method
  85. End Sub
Dec 12 '09 #2
ADezii
8,834 Recognized Expert Expert
A couple of items immediately stood out, but I am not really sure if they are relevant.
  1. You do not need to check the Selected Property of each Item in the ItemsSelected Collection, since these Items by nature are already Selected. This is redundant. Your For...Next Loops should read:
    Expand|Select|Wrap|Line Numbers
    1. Dim valSelect As Variant
    2. Dim mySQL As String
    3. Dim valSel As String
    4.  
    5. For Each valSelect In Me.lstTrendChoice.ItemsSelected
    6.   mySQL = mySQL & " tblSampleResults." & Me.lstTrendChoice.ItemData(valSelect) & ","
    7.     valSel = (Me.lstTrendChoice.ItemData(valSelect))
    8. Next valSelect
    9.  
    Expand|Select|Wrap|Line Numbers
    1. For Each valSelect In Me.Combo7.ItemsSelected
    2.   If firstEquip Then
    3.     mySQL = mySQL & " And (tblEquipment.equipmentID=" & Me.Combo7.ItemData(valSelect)
    4.       firstEquip = False
    5.   Else
    6.     mySQL = mySQL & " OR tblEquipment.equipmentID=" & Me.Combo7.ItemData(valSelect)
    7.   End If
    8. Next valSelect
  2. Unless I missed something, I see no relevance as far as the valSel Variable is concerned (Code Line #7 above - first Code Block)
  3. Kindly put your Code within Code Tags along with the proper indentation, and I'll be happy to look at it in more detail. Repost the Code if necessary.
Dec 12 '09 #3
CoreyReynolds
29 New Member
Sorry about the code - the option wasn't there (I'm not sure why).
I did figure out what the issue was - when I changed an option in the designer Access kind of just went "Well look at all this ugly code! Let me clean it up for you!" and did something that made it work in the process of reorganizing. That "thing" was a parenthesis issue. I just figured out what it did and changed it into my code.

I also updated it with your suggestions and everything is tip top.

In closing: Access saw and error and fixed it (wait what??? :) )
Dec 12 '09 #4
missinglinq
3,532 Recognized Expert Specialist
BTW, Corey, you have to click on the "Go Advanced" button below the editing screen to add code tags with an icon. From there hilite the code and click on the pound (#) sign.

Linq ;0)>
Dec 12 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2028
by: Francisco | last post by:
I have this question: I have a simple search to a db, something like: "select description from games where year = '1990'" suppose I get 300 results, I would like to display this in pages of 30 results per page, so I would use "limit 0, 30" for the first page. But this way, I don't know how many results would I have if I didn't use "limit". So how do I know if I have more than one page to display?, the only way I can thing is to do the...
8
2959
by: Frnak McKenney | last post by:
Back when computer dinosaurs roamed the earth and the precursors to today's Internet were tiny flocks of TDMs living symbiotically with the silicon giants, tracking access to data processing resources was much simpler: you logged in with a userID and password, and when you were done you ended your session by logging out (or occasionally by being disconnected). Connection time was easy to measure, and it made sense to both the customer...
2
3436
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the new values are updated in all corresponding tables (the function of the pages in question). However, on the page that does the DB update, I also want to do some checks on the data before performing the update. Now, the problem that I am...
5
3324
by: will eichert | last post by:
Greetings. I have a problem with a combo box incorrectly displaying blank items when returning to a form from a modal form. It's fine when the main form first comes up, but gets messed up when the main form is reactivated following opening and closing a modal form. Strangely, this was not a problem until I started using my Access 2000 db in Access 2003 (as an Access 2000 db). Details follow... I have an unbound combo box on my main form...
0
1545
by: Stu | last post by:
I have a few FrontPAGE 2002 Webs running on Windows 2003 Servers and IIS. My webs use ASP (classic) pages that display data pulled from the Access databases using the FrontPage database results wizard - displaying query results, etc. from my main database. It works fine when the database contains the tables/data but when the tables are linked to external tables within *.mdb files (located in the same web folder - /fpdb) or if I split the...
6
1896
by: Stuart Clark | last post by:
Hiya I'm learning ASP using Access and Dreamweaver. I've just started simple and I've tried to make the db show the results of just two tables without doing anything clever! I have the following code: <!--#include file="Connections/imaildata.asp" --> <% Dim rsData Dim rsData_numRows
0
2627
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to find one, I'm posting the question in hope some one of you guys out there will have the answer for me...! I'll start with what I have, then I'll continue to the problem itself.
9
3949
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result - I have read every post out there and spent hours trying to figure out the problem with no success whatsoever - I have constrained the problem to one form however, and I think it's hiding somewhere in my code associated with this form, which is...
0
2764
by: uno7031 | last post by:
Help Please!!! Adding 5 Days to another Date in an access query Good Morning, Help please…. I am new to access and trying to write a query that will add 5 days between a RecDate and a DLPayDate I created the query in design view of access. Current Query: SELECT PaymentCalculator2.ID, PaymentCalculator2.RecDate, DateAdd("w",5+1,) AS DLPayDate, DateAdd("w",5,) AS DLPayDate2 FROM PaymentCalculator2 WHERE...
0
9710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9589
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10593
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6858
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.