Hi John
thanks for your response and to show me how little knowledge I have, for
that what I am planning to do - I do not understand anything from your code.
Does your code mean that I have to do my sql as follows?
Private Sub Command29_Click()
Dim stDocName As String
Dim db As DAO.Database
Dim qd1 As DAO.Querydef
Dim qd2 As DAO.Querydef
Set db = CurrentDb
Set qd1 = db.Querydefs("billcemeteryyear")
qd1.Execute, dbFailOnError
<you can look at qd1.RecordsAffected to see how many were>
qd2.Execute, dbFailOnError
Set qd1 = Nothing
Set qd2 = Nothing
Dim db As DAO.Database
Dim qd1 As DAO.Querydef
Dim qd2 As DAO.Querydef
Set db = CurrentDb
Set qd1 = db.Querydefs("billcemeteryhalfyear")
qd1.Execute, dbFailOnError
<you can look at qd1.RecordsAffected to see how many were>
qd2.Execute, dbFailOnError
Set qd1 = Nothing
Set qd2 = Nothing
End Sub
Please, I am totally lost - can you explain to me in easy words what your
code is doing? or, if it is not asked to much to alter my code?
Thanks
Well, that code doesn't much resemble what I posted... <g>
It's not SQL (the language of queries); it's VBA, Visual Basic for
Applications, the language of modules. You had posted some VBA code which
executes two queries; I posted some alternative VBA code to execute those same
two queries.
Here's what I'd suggest that you use. Change the button name from Command29 to
something meaningful - cmdRunBills let's say - just so you can understand the
code yourself later.
Private Sub cmdRunBills_Click()
Dim db As DAO.Database ' define a Database object
Dim qd1 As DAO.Querydef ' define two Querydef objects
Dim qd2 As DAO.Querydef
On Error GoTo Proc_Error ' set up an error trap
Set db = CurrentDb ' set the Database object to the current database
Set qd1 = db.Querydefs("billcemeteryyear") ' select your first action query
qd1.Execute, dbFailOnError ' run it; if there's an error it will be trapped
MsgBox "Bill Cemetery Year query affected " & qd1.RecordsAffected & " records"
Set qd2 = db.Querydefs("billcemeteryhalfyear") ' select the next query
qd2.Execute, dbFailOnError ' run it
MsgBox "Bill Cemetery Half-year affected " & qd2.RecordsAffected & " records"
Proc_Exit:
On Error Resume Next ' ignore any errors in the cleanup
Set qd1 = Nothing ' clean up after yourself
Set qd2 = Nothing
Exit Sub
Proc_Error: ' any errors come here
' Display the error on the screen
MsgBox "Error " & Err.Number & " in cmdRunBills_Click:" & vbCrLf _
& Err.Description
Resume Proc_Exit ' after displaying the error, just quit
End Sub
COpy this entire program into the Click event code of your command button;
select Debug... COmpile; correct any errors or post back for help doing so.
John W. Vinson [MVP]