Solved Convert query to sql programatically (1 Viewer)

Dumferling

Member
Local time
Today, 15:45
Joined
Apr 28, 2020
Messages
102
Is there a reasonably simply way to convert a query to as sql statement and insert that into the rowsource of a listbox programatically? I have several queries for one list box and I swop them out according to the need to look at different information. I want to rather have a sql statement in the rowsource (literally a SELECT etc) rather than the queryname. The reason is I have code which allows me to sort any field by rightclicking on the column but it requires a sql statement in the rowsource of the listbox.

I could create a table and store each sql statement in but it seems a bit roundabout. If there a vba function that can do the conversion?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:45
Joined
May 7, 2009
Messages
19,169
you can get the SQL of the query and use it as rowsource:

Dim db As DAO.Database
Dim strSQL As String
Set db = CurrentDb
strSQL = db.QueryDefs("theQueryName").SQL
Set db = Nothing
Debug.Print strSQL
 

Dumferling

Member
Local time
Today, 15:45
Joined
Apr 28, 2020
Messages
102
you can get the SQL of the query and use it as rowsource:

Dim db As DAO.Database
Dim strSQL As String
Set db = CurrentDb
strSQL = db.QueryDefs("theQueryName").SQL
Set db = Nothing
Debug.Print strSQL
Thank you. This worked perfectly!
 

Users who are viewing this thread

Top Bottom