G
Guest
Is there a way to run a delete query or a make table from a macro or from an
event procedure?
Will
event procedure?
Will
Is there a way to run a delete query or a make table from a macro or from an
event procedure?
Will
John Vinson said:Certainly. Several in fact. <g>
In a Macro you can use the RunQuery action.
Better, because it traps errors and lets you check results, is to use
an event procedure. The Execute method traps query errors and avoids
the annoying prompts that you may otherwise get:
Dim db As DAO.Database
Dim qd As DAO.Querydef
Dim prm As Parameter
On Error GoTo Proc_Error
Set db = CurrentDb
Set qd = db.Querydefs("YourQueryName")
' the following lets you use Parameter queries; you can omit if the
' query has no parameters
For Each prm In qd.Parameters
prm.Value = Eval(prm.Name)
Next prm
' execute the query
qd.Execute dbFailOnError
If qd.RecordsAffected = 0
<warn the user that the query didn't do anything>
End If
Proc_Exit:
Exit Sub
Proc_Error:
MsgBox "The query didn't work: Error " & Err.Number _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub
John W. Vinson[MVP]