From out there on the moon, international politics look so petty. You want to grab a politician by the scruff of the neck and drag him a quarter of a million miles out and say, "Look at that!"
Hi Richard. In response to your inquiry for future seminars and access lessons, I would suggest an comprehensive seminar on syntax. I always understand what i need to put in my sql statement but I always err when it come to the syntax. I loose hours on a missing space or quotation mark. It's quite frustrating to waste time on syntax, wish there was a complete guide somewhere.
For a specific example : on a form I have two buttons that load a report based on the value loaded in txt box.
The first button loads the report based on on an id (number) works great. WHERE "[RubricID]=" & [GbselectedrubricID]
The second button loads the report according to a second text box (date). WHERE "[Dateofeval]=" & "#" & [GBdateselected] & "#"
These two button work great on their own but when I combine them into one WHERE "[Dateofeval]=" & "#" & [GBdateselected] & "#" AND "[RubricID]=" & [GbdateselectedID] Does not work, logically it should work I do not understand why, I blame it on syntax. Marc
Reply from Alex Hedley:
You need to be careful with where your quotes are. 1 tip would be to write the whole WHERE in quotes first "WHERE [RubricID]=1" Now you want to replace the 1 with a variable x "WHERE [RubricID]=" & x
WHERE "[RubricID]=" & [GbselectedrubricID] => "WHERE [RubricID]=" & [GbselectedrubricID]
You need to move the quote here and you don't need the extra & WHERE "[Dateofeval]=" & "#" & [GBdateselected] & "#" => "WHERE [Dateofeval]=#" & [GBdateselected] & "#"
WHERE "[Dateofeval]=" & "#" & [GBdateselected] & "#" AND "[RubricID]=" & [GbdateselectedID] => "WHERE [Dateofeval]=#" & [GBdateselected] & "# AND [RubricID]=" & [GbdateselectedID]
Do you see how you've closed your quote too early & "#" AND "[Ru ...
Another option is to build the Query first in the Query Builder. Change to SQL View Copy Paste this into your VBA, then switch out the values for variables
You could also build your strSQL string then Debug.Print strSQL Then you can see what you've built.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access SQL Seminar Part 2.