On Print error

DBL

Registered User.
Local time
Today, 19:52
Joined
Feb 20, 2002
Messages
659
I have a two stage event on a report. If the user hasn't printed the report by the time they click close it prompts them using the following:

Private Sub Report_Close()
Dim stdResponse As Integer
Dim Cancel As Integer


If Flag = 2 Then

stdResponse = (MsgBox("You have not printed these letters, do you want to do that now?", vbYesNo, "Print Letters"))

If stdResponse = vbYes Then
Cancel = True
ReportPrint 'Function
Forms!frmHAServiceLettersPrintDialog.List21.Requery

End If

End If
Flag = 0
If IsLoaded("frmHAServiceLettersPrintDialog") Then Forms!frmHAServiceLettersPrintDialog.Visible = True

End Sub


if they want to print the report the ReportPrint function kicks in:

Dim db As Database
Dim rs As DAO.Recordset
Dim result As String
Set db = CurrentDb
Dim msg As String

Dim stdResponse As Integer
Dim Cancel As Integer



If Flag = 2 Then

stdResponse = (MsgBox("You are about to print service letters for the selected properties." & vbCr & vbCr & _
"Do you want to update the property records to show the service letters have been printed?", vbYesNo, "Update Records"))

If stdResponse = vbYes Then
Cancel = True
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryUpdateSLSent"
DoCmd.SetWarnings True
Flag = 0

DoCmd.PrintOut

Else
Cancel = True
MsgBox "You cannot print these letters at this time."
Exit Function
End If
End If


I'm getting an error 2585 "this action can't be carried out while processing a form or report event"

It's highlighting the DoCmd.PrintOut when I step through the code. Any idea what's stopping the code from running - I'm assuming it's because the other code is on the Close event of the report - but how can I cancel the close event and let the ReportPrint function do it's thing?

Thanks
 
One of the things Access does when performing any vba is to read it all first checking for syntax errors then programming errors, finally logical errors. If none are found it it perfroms the sql. Your problem is that is trying to memorise your code and the latter cannot be done until the former is coompleted. Unlike VB that reads and perfroms code one line at a time. You may find that using DoEvents at certain places in the code will render Access to complete one process before moving onto the next stage.
 
Doh! I was running the DoCmd.PrintOut after I'd run an update query which removed the records from the recordset!

Thanks for the information on the DoEvents. That's something I think I'll be introducing into my code a bit more.
 

Users who are viewing this thread

Back
Top Bottom