What Do You Use Instead of DoCmd.OpenQuery or DoCmd.RunSQL

M

Mr. JYC

Hello,

What do you use to open a query that is stored within a string variable in
datasheet view? Is recordsets the only way? I just want to open it in
datasheet like a query that was just designed in design view.

It seems that DoCmd.OpenQuery uses a stored query and DoCmd.RunSql just runs
action queries.

Could someone help?
 
D

Douglas J. Steele

You could create a query and open it:

Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef
Dim strSQL As String

strSQL = "SELECT * FROM Groups"
Set dbCurr = CurrentDb()
Set qdfCurr = dbCurr.CreateQueryDef("temp", strSQL)
DoCmd.OpenQuery "temp"
dbCurr.QueryDefs.Delete "temp"
Set dbCurr = Nothing
 
M

Mr. JYC

Thank you Douglas!
--
Thank you for your help!
JYC


Douglas J. Steele said:
You could create a query and open it:

Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef
Dim strSQL As String

strSQL = "SELECT * FROM Groups"
Set dbCurr = CurrentDb()
Set qdfCurr = dbCurr.CreateQueryDef("temp", strSQL)
DoCmd.OpenQuery "temp"
dbCurr.QueryDefs.Delete "temp"
Set dbCurr = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top