neillovell
Programmer
I can use VBA to UPDATE and INSERT entries into table, but what about regular queries? For example, I want the VBA equivilent of creating a new query from the Queries control panel, and running it (so the results appear on the screen).
Here is some simple VBA code that performs a query, but there is no command to show it to the user. What would that command be? I can't find anything useful in the DoCmd object, as OutputTo sends a saved query to a file.
Dim DatabaseConnection As ADODB.Connection
' Set the connection to the DB
Set DatabaseConnection = Application.CurrentProject.Connection
' Get the name of the person to add
' Text between speech marks is copied in as-is, while that outside of it (i.e. & Name & and & Number &)
' has the value extracted from the variables.
' Be sure that single quotes, that must go around strings, are included as-is !
SQL = "SELECT * From MyTable"
DatabaseConnection.Execute SQL
Here is some simple VBA code that performs a query, but there is no command to show it to the user. What would that command be? I can't find anything useful in the DoCmd object, as OutputTo sends a saved query to a file.
Dim DatabaseConnection As ADODB.Connection
' Set the connection to the DB
Set DatabaseConnection = Application.CurrentProject.Connection
' Get the name of the person to add
' Text between speech marks is copied in as-is, while that outside of it (i.e. & Name & and & Number &)
' has the value extracted from the variables.
' Be sure that single quotes, that must go around strings, are included as-is !
SQL = "SELECT * From MyTable"
DatabaseConnection.Execute SQL