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: - SELECT tblEquipment.equipmentID, tblSample.sampleDate, tblSampleResults.Chromium, IIf([x]=True,'X',(IIf([u]=True,'U',' '))) AS Critical
-
-
FROM (((tblEquipment
-
INNER JOIN tblCompartment ON tblEquipment.[equipmentID] = tblCompartment.[equipmentID])
-
INNER JOIN tblSample ON tblCompartment.[compartmentAutoID] = tblSample.[compartmentSpecific])
-
INNER JOIN tblSampleResults ON tblSample.[sampleNumber] = tblSampleResults.[sampleCode])
-
LEFT JOIN tblSignificant ON tblSampleResults.sampleID = tblSignificant.sampleCode
-
-
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)
-
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'))
-
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! :(
4 1723
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. - Private Sub btnTrend_Click()
-
-
'Create Query
-
Dim query As String
-
Dim db As Database
-
Dim rs As Recordset
-
Set db = CurrentDb
-
Dim mySql As String
-
Dim valSelect As Variant
-
Dim strValue As String
-
Dim firstEquip As String
-
firstEquip = True
-
Dim ValSelectE As Variant
-
Dim strValueE As String
-
Dim valSel As String
-
-
-
-
-
Dim chartLabel As String
-
chartLabel = "Sample Result Trending - " & Me.lstCompChoice.Column(1) & " : " & Me.equipmentID.Value & " [" & Me.equipmentDescription.Value & "]"
-
'Ensure proper information is selected
-
If Me.lstCompChoice.ItemsSelected.Count > 0 And Me.lstTrendChoice.ItemsSelected.Count > 0 And Me.txtDateStart <> "" And Me.txtDateEnd <> "" Then
-
-
'Create begining of query
-
mySql = "SELECT tblEquipment.equipmentID, tblSample.sampleDate, "
-
-
-
'This section just adds the particular component to the SQL String
-
For Each valSelect In Me.lstTrendChoice.ItemsSelected
-
If lstTrendChoice.Selected(valSelect) Then
-
mySql = mySql & " tblSampleResults." & Me.lstTrendChoice.ItemData(valSelect) & ","
-
valSel = (Me.lstTrendChoice.ItemData(valSelect))
-
-
End If
-
Next valSelect
-
mySql = mySql & " IIf([x]=True,'X',(IIf([u]=True,'U',' '))) AS Critical,"
-
'Clip last useless comma
-
mySql = Left(mySql, Len(mySql) - 1)
-
-
'Create query to turn into chart
-
mySql = mySql & " FROM (((tblEquipment INNER JOIN tblCompartment ON tblEquipment.[equipmentID] = tblCompartment.[equipmentID])" & _
-
" INNER JOIN tblSample ON tblCompartment.[compartmentAutoID] = tblSample.[compartmentSpecific]) INNER JOIN" & _
-
" tblSampleResults ON tblSample.[sampleNumber] = tblSampleResults.[sampleCode] " & _
-
") Left JOIN tblSignificant ON tblSampleResults.sampleID = tblSignificant.sampleCode" & _
-
" WHERE tblCompartment.compartmentCode=" & Me.lstCompChoice.Value
-
-
'Insert conditional of equipment loop
-
For Each valSelect In Me.Combo7.ItemsSelected
-
If Me.Combo7.Selected(valSelect) Then
-
If firstEquip Then
-
mySql = mySql & " And (tblEquipment.equipmentID=" & Me.Combo7.ItemData(valSelect)
-
firstEquip = False
-
Else
-
mySql = mySql & " OR tblEquipment.equipmentID=" & Me.Combo7.ItemData(valSelect)
-
End If
-
End If
-
Next valSelect
-
-
mySql = mySql & ") AND (tblSample.sampleDate >= #" & Me.txtDateStart.Value & "# and tblSample.sampleDate <= #" & Me.txtDateEnd.Value & "#)"
-
mySql = mySql & "AND (tblSignificant.field ='" & Replace(Me.lstTrendChoice.Value, " ", "") & "' OR tblSignificant.field = null)" & " ORDER BY tblEquipment.equipmentID ASC;"
-
-
'delete if old temp query exists
-
Dim qdf As Variant
-
For Each qdf In db.QueryDefs
-
If qdf.Name = "qryTemp" Then
-
db.QueryDefs.Delete "qryTemp"
-
Exit For
-
End If
-
Next
-
-
-
'create new query
-
-
db.CreateQueryDef "qryTemp", mySql
-
-
CreateDAOChartM "qryTemp", valSel
-
-
-
-
-
End If
-
-
'Pass Query into chart creation method
-
End Sub
ADezii 8,834
Recognized Expert Expert
A couple of items immediately stood out, but I am not really sure if they are relevant. - 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:
-
Dim valSelect As Variant
-
Dim mySQL As String
-
Dim valSel As String
-
-
For Each valSelect In Me.lstTrendChoice.ItemsSelected
-
mySQL = mySQL & " tblSampleResults." & Me.lstTrendChoice.ItemData(valSelect) & ","
-
valSel = (Me.lstTrendChoice.ItemData(valSelect))
-
Next valSelect
-
- For Each valSelect In Me.Combo7.ItemsSelected
-
If firstEquip Then
-
mySQL = mySQL & " And (tblEquipment.equipmentID=" & Me.Combo7.ItemData(valSelect)
-
firstEquip = False
-
Else
-
mySQL = mySQL & " OR tblEquipment.equipmentID=" & Me.Combo7.ItemData(valSelect)
-
End If
-
Next valSelect
- Unless I missed something, I see no relevance as far as the valSel Variable is concerned (Code Line #7 above - first Code Block)
- 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.
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??? :) )
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)> Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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
|
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.
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |