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

  • Thread starter Thread starter Mr. JYC
  • Start date Start date
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?
 
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
 
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
 
Back
Top