A family of Microsoft relational database management systems designed for ease of use.
The Execute method executes an 'action' query; it does not open a query in datasheet view, which I assume is what you are attempting. For this sort of 'on the fly' task I use the following function:
Public Function OpenTempQuery(strSQL As String)
Dim qdf As DAO.QueryDef
Static n As Integer
n = n + 1
' delete temporary querydef object if exists
On Error Resume Next
CurrentDb.QueryDefs.Delete "Temp" & n
Select Case Err.Number
Case 0
' no error
Case 3265
' temporary querydef does not exist
' ignore error
Case Else
' unknown error
MsgBox Err.Number, vbExclamation, "Error"
End Select
' create temporary querydef object
Set qdf = CurrentDb.CreateQueryDef("Temp" & n)
CurrentDb.QueryDefs("Temp" & n).SQL = strSQL
' open query and then delete temporary querydef object
DoCmd.OpenQuery "Temp" & n
' delete temporary querydef object
CurrentDb.QueryDefs.Delete "Temp" & n
End Function
Call it like this:
OpenTempQuery "SELECT [mess] FROM [etypes] WHERE [etypecode] = 'CURR'"
Because the integer variable n is declared as Static, giving each temporary querydef object's name a distinct suffix, the function can be called multiple times while leaving each datasheet open. This can be useful for ad hoc 'what if?' comparisons, which is why I wrote it in the first place.