koolwaters
Active Member
- Joined
- May 16, 2007
- Messages
- 403
I have an option group on my form with two options. I have a combo box where the user can select the employee whose details they want to see based on either option from the option group.
There is a commnad button to preview the reports. I can either select an employee to see that employee's records or not select an employee and view all the records. The OnNoData event of the two reports which can be opened from the option group are set to: docmd.CancelEvent.
I have copied some common form error codes as part of a module as below:
Public Const errCancel As Long = 2501
Public Const errCancel2 As Long = 2001
If I select an employee who has records, the report is opened. If I select an employee who does not have any records I get Run-time error '2501': The OpenReport action was cancelled.
The code that I have in the On_Click event of the command button is below.
When I debug, the line of the code that I have in bold typeface is the line that is highlighted.
I have been at it for a while but I cannot figure out what is wrong. Please help.
Thanks in advance.
There is a commnad button to preview the reports. I can either select an employee to see that employee's records or not select an employee and view all the records. The OnNoData event of the two reports which can be opened from the option group are set to: docmd.CancelEvent.
I have copied some common form error codes as part of a module as below:
Public Const errCancel As Long = 2501
Public Const errCancel2 As Long = 2001
If I select an employee who has records, the report is opened. If I select an employee who does not have any records I get Run-time error '2501': The OpenReport action was cancelled.
The code that I have in the On_Click event of the command button is below.
Rich (BB code):
Private Sub cmdPreviewClients_Click()
Dim varWhere As Variant, strReport As String
On Error GoTo Err_cmdPreviewClients_Click
varWhere = Null
If Not IsNothing(Me.cboEmployee) Then
varWhere = "[EmployeeName] LIKE '" & Me.cboEmployee & "*'"
End If
If IsNothing(varWhere) Then
If vbNo = MsgBox("You did not select an Employee." & vbCrLf & vbCrLf & "Do you want to print the report for all clients?", _
vbYesNo + vbQuestion + vbDefaultButton2) Then
Exit Sub
Else
varWhere = "1 = 1"
End If
End If
If Me.optReports = 1 Then
strReport = "Clients by Employee"
Else
strReport = "Client Meeting this Month by Employee"
End If
DoCmd.OpenReport strReport, acViewPreview, WhereCondition:=varWhere DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100
DoCmd.SelectObject acReport, strReport
Exit_cmdPreviewClients_Click:
Exit Sub
Err_cmdPreviewClients_Click:
If (Err = errCancel2) Then
MsgBox "There are no clients assigned to " & cboEmployee & ". The report was cancelled.", , "Client Management: Report Cancelled"
Else
MsgBox "There are no meetings assigned to " & cboEmploee & ". The report was cancelled.", , " Client Management: Report Cancelled"
End If
Resume Exit_cmdPreviewClients_Click
End Sub
When I debug, the line of the code that I have in bold typeface is the line that is highlighted.
I have been at it for a while but I cannot figure out what is wrong. Please help.
Thanks in advance.