Here is the code:
Sub RunAQuery(ByVal pQueryToRun As String)
'Written by Stuart Smith
' Seguin Software
On Error GoTo Err_RunAQuery
DoCmd.SetWarnings False
DoCmd.OpenQuery pQueryToRun, acNormal, acEdit
Exit_RunAQuery:
DoCmd.SetWarnings True
Exit Sub
Err_RunAQuery:
MsgBox Err.Description
Resume Exit_RunAQuery
End Sub
I turn off the warnings and when the querie is done, turn them back on. I put the SetWarning True in the subroutine exit area to make sure they get turned back on in case of an error.