Not in a Macro, you can't
Public Function RunQuery(ByVal inSQL As String, Optional ByVal ODBCConnect
As String=VBA.vbNullString) As Long
Dim RQDb As DAO.Database
Dim RQQDef As DAO.QueryDef
Dim thQ As String
Dim oldErr As DAO.Error
Dim Parm As DAO.Parameter
On Local Error Resume Next
Set oldErr = DAO.Errors(0)
VBA.Err.Clear
Set RQDb = Access.CurrentDb()
Set RQQDef = RQDb.QueryDefs(inSQL)
If VBA.Err.Number <> 0 Then ' Temp Query
Set RQQDef = RQDb.CreateQueryDef(VBA.vbNullString)
With RQQDef
If VBA.Len(ODBCConnect) > 0 Then
.ReturnsRecords = False
.Connect = ODBCConnect
End If
.SQL = inSQL
End With
End If
VBA.Err.Clear
With RQQDef
If VBA.Len(ODBCConnect) = 0 Then
For Each Parm In .Parameters
Parm.Value = Access.Eval(Parm.Name) 'Assumes Parameters refer to
Forms Controls
Next
End If
VBA.Err.Clear
If VBA.Len(ODBCConnect) = 0 Then
.Execute DAO.dbSeeChanges + DAO.dbConsistent + DAO.dbFailOnError
Else
.Execute
End If
RunQuery = .RecordsAffected
End With
If ShowErr And VBA.Err.Number <> 0 Then
ODBCError
VBA.Err.Clear
Else
If VBA.Err.Number <> 0 Then
Debug.Print "[RunQuery]", inSQL
Debug.Print VBA.Err.Number, VBA.Err.Description
End If
If Not oldErr Is Nothing Then
VBA.Err.Raise oldErr.Number, oldErr.Source, oldErr.Description ' Keep
Error State
End If
End If
RQQDef.Close: Set RQQDef = Nothing
Set RQDb = Nothing
End Function
HTH
Pieter