Microsoft Access VBA Macro Programming

(Tina Sui) #1

One interesting point about the treatment of dates is that in the actual SQL query behind
this GUI, the date is always changed to the mm/dd/yyyy format if it is in the dd/mm/yyyy
format (regardless of the locale settings). It is important to realize this when putting together
SQL for use inside of VBA.
Click the Run icon or the View | Datasheet icon in the results group of the ribbon and you
will see all the records returned.
Click the drop-down from the View icon in the Results group of the ribbon and Select
SQL View. This will display the SQL statement for the query you have constructed:


SELECT Customers.Company, Orders.[Order Date], Orders.[Ship Name]
FROM Customers RIGHT JOIN Orders ON Customers.ID = Orders.[Customer ID]
WHERE (((Orders.[Order Date])>#1/1/2006#));


Save this query with the name ofMyQuery.
The SQL statement is what you will incorporate into your VBA code. If you have a good
knowledge of SQL, you can write it out in the SQL window without bothering with the GUI
front end, although it is easy to make mistakes doing this. The GUI front end will still reflect
your SQL.


Chapter 12: SQL Queries 153


Figure 12-4 A Query Design window with fields and criteria added

Free download pdf