qrydef

crowegreg

Registered User.
Local time
Yesterday, 17:53
Joined
Feb 28, 2011
Messages
108
I can't figure out the correct vba code to make a query out of a select statement.


SELECT [tbl Import IPG Raw].Date, [tbl Import IPG Raw].Title
FROM [tbl Import IPG Raw]

Thanks in advance!!
 
Try;
Code:
"SELECT [tbl Import IPG Raw].Date, [tbl Import IPG Raw].Title " & _
"FROM [tbl Import IPG Raw];"
Note, the space between the end of the first line and the closing quotation mark on that line, or alternately; simply put it on one line
Code:
"SELECT [tbl Import IPG Raw].Date, [tbl Import IPG Raw].Title FROM [tbl Import IPG Raw];"
 
As an aside avoid using spaces and other special characters in object and control names, limit your self to alpha and numeric characters and the underscore.
 
Thanks for the quick reply. I didn't write my question well enough. If I have a select statement, how do I go about creating a query that can be selected from the query object list?
 
If I've understood you correctly; First double click on the "Create Query in Design View" Icon at the top of the list, Close the Table selector Dialogue box. Now Right Click on the design grid header bar and select SQL View from the list, paste your SQL into the window and save your query.
 
Thanks, we're getting a closer. If within the vba code behind a form, I have created a select statement based on selections the user has made on the form. I'd like to have VBA that would create a query based on the select statment. I'd like for this query to be displayed on the query list.
 
So if the user is dynamically creating a query based on the selections they have made in a form, why does that query need to be saved and available from the Query Object window :confused:
 
I then need to export the query results to an excel file. I have found similar code that will edit a query already in existance, I'd like to just create the query. Here's what I've found:

Dim db As DAO.Database
Dim qdf As DAO.QueryDef

Set db = CurrentDb
Set qdf = db.QueryDefs("testgreg")

qdf.SQL = "SELECT [tbl Import IPG Raw].Date, [tbl Import IPG Raw].Title FROM [tbl Import IPG Raw];"
 

Users who are viewing this thread

Back
Top Bottom