Timer event help please ! Thanks, Steve

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi,
Have the following code in the timer section of a form
which runs 3 reports at 15 second intervals. If there is
no data in a report there is a cancel event

Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub

which keeps a blank report from printing out but ALSO
seems to end the timer event and not run the other report.
What am i missing ?

Private Sub Form_Timer()
On Error GoTo Err_cmdPrintBarCodeLabelsTIMER_Click

Dim stDocName As String


If Time() > "7:30 PM" Then
DoCmd.Quit
End If

DoCmd.SetWarnings False
'CARL SECTION
stDocName = "rptReceiverBarCodeLabelsCARL"
DoCmd.OpenReport stDocName, acNormal 'acPreview
DoCmd.Close acReport, stDocName, acSaveNo

'ORLANDO SECTION
stDocName = "rptReceiverBarCodeLabelsORLANDO"
DoCmd.OpenReport stDocName, acNormal 'acPreview
DoCmd.Close acReport, stDocName, acSaveNo

'TONYA SECTION
stDocName = "rptReceiverBarCodeLabelsTONYA"
DoCmd.OpenReport stDocName, acNormal 'acPreview
DoCmd.Close acReport, stDocName, acSaveNo

DoCmd.SetWarnings True

Err_cmdPrintBarCodeLabelsTIMER_Click:
Exit Sub
End Sub
 
Steve said:
Hi,
Have the following code in the timer section of a form
which runs 3 reports at 15 second intervals. If there is
no data in a report there is a cancel event

Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub

which keeps a blank report from printing out but ALSO
seems to end the timer event and not run the other report.
What am i missing ?

Private Sub Form_Timer()
On Error GoTo Err_cmdPrintBarCodeLabelsTIMER_Click

Dim stDocName As String


If Time() > "7:30 PM" Then
DoCmd.Quit
End If

DoCmd.SetWarnings False
'CARL SECTION
stDocName = "rptReceiverBarCodeLabelsCARL"
DoCmd.OpenReport stDocName, acNormal 'acPreview
DoCmd.Close acReport, stDocName, acSaveNo

'ORLANDO SECTION
stDocName = "rptReceiverBarCodeLabelsORLANDO"
DoCmd.OpenReport stDocName, acNormal 'acPreview
DoCmd.Close acReport, stDocName, acSaveNo

'TONYA SECTION
stDocName = "rptReceiverBarCodeLabelsTONYA"
DoCmd.OpenReport stDocName, acNormal 'acPreview
DoCmd.Close acReport, stDocName, acSaveNo

DoCmd.SetWarnings True

Err_cmdPrintBarCodeLabelsTIMER_Click:
Exit Sub
End Sub

When your report's NoData event cancels the opening of the report, that
is reflected as an error (2501) raised for the DoCmd.OpenReport
statement in the form's Timer event procedure. You must change your
error-handling procedure to trap and ignore that error. Modify it as
follows:

'----- start of replacement code -----
Err_cmdPrintBarCodeLabelsTIMER_Click:
If Err.Number = 2501 Then
' OpenReport was cancelled -- ignore it and continue.
Resume Next
Else
' A real error has occurred, so quit.
Exit Sub
End If
'----- end of replacement code -----

Personally, I'd also add a MsgBox call to display the error number and
description, in the event of a "real error", but that's up to you.
 
Back
Top