You can use code to create a query and save it. For instance, the following
will create a query named TempQuery and open the query.
Public Sub showquery()
'Untested Sample code
Dim qdfAny As QueryDef
Dim dbany As DAO.Database
Dim strSQL As String
Set dbany = CurrentDb()
strSQL = "SELECT * FROM SomeTable"
Set qdfAny = dbany.CreateQueryDef("TempQuery", strSQL)
DoCmd.OpenQuery "tempquery"
End Sub
If you only want to display the results on a form, you could assign the SQL
string as the record source of a form. If I recall correctly, the length of
the string is limited to 2K characters so if your SQL string is longer than
that you would still need to create and store the query.
Recordsets are good for manipulating data in VBA, but generally are not so
good for displaying the data in the user interface.
"JT Santa Fe" <(E-Mail Removed)> wrote in message
news:EBE4BA9F-2844-4FE4-8F45-(E-Mail Removed)...
> Thanks -
> How do you save the SQL statement as a query without going into the native
> mode? How to you get the SQL to create a recordset as you wrote? Any
> examples would help.
> Thanks
>
> "John Spencer" wrote:
>
>> RunSQL can only be used with ACTION queries. A UNION query is not an
>> action
>> query - it does not add, delete, or modify any records.
>>
>> You can save the SQL statement as a query and open the query. Or you can
>> use the SQL to create a recordset.
>>
>>
>> "JT Santa Fe" <JT Santa (E-Mail Removed)> wrote in message
>> news:26E8F0A3-9A28-4C49-AB59-(E-Mail Removed)...
>> >I have an application that tables are standardized but can be created
>> >form
>> > menus by the users. I need to be able to regenerate a union query that
>> > reads
>> > all the standardized tables (i.e., tblDimen_XXX, tblDimenYYY). I have
>> > the
>> > code that creates the SQL variable in VBA, but I get a error message
>> > that
>> > I
>> > need a valide SQL statement. Things that I read indicate creating
>> > unioun
>> > queries from SQL are not allowed ?!?!?!?!?
>>
>>
>>