I want to do something simple, run a query when a form is closed. I have the following code to do it and Access does't like the syntax. I've tried putting the query name in brackets and that didn't help either.
ption Compare Database
Private Sub Form_Close()
docmd.OpenQuery(find unmatched append query for results and limits,acViewNormal,acEdit)
Take a look at the code below taken directly from my own database where
I run queries, but in a different way.
Private Sub cmbProcessJobCharge_Click()
On Error GoTo Err_cmbProcessJobCharge_Click
' Written by "Bud" and passed to DB Forums user for an example.
'This Prints out the job charge report,saves the records and closes the form'
Dim stDocName As String
stDocName = "JobCharge"
DoCmd.GoToRecord , , acNewRec
DoCmd.OpenReport stDocName, acNormal
stDocName = "LaunchPad.PostJobCharge"
CurrentDb.Execute "PostJobCharge"CurrentDb.Execute "UpdateStockedItems"
'MsgBox "Your records have been processed." & Chr(13) _
'& "Thank you and have a nice day!", vbExclamation, "Job Charged Notice"
Note: the words in BOLD is the command that runs the queries,
and at the same time avoids the Access Warning Messages you get and doing
so this way avoids having to do the: SetWarnings/True and False as users have often times to set the
warnings back to True in the end. No muss, no fuss.
Note: the Italics are the names of my queries
As suggested by sionus, IF that was the actual name of your Query, then
by all means think of Re-Naming to something shorter, neater and meaningful.
That will save lots of typing and typos.
Anyway, now you have choices and hope either one gets you what you need.
If not come back and let another somebody take a whack at ya...