I have a form called frmOccurrence(This form stays open when the other form is clicked) in which I have a button that opens a form called frmSelectOccurrenceEmploye
e in which I capture the field called cboEmployee a beginning date called txtbegdate and an ending date called txtenddate. These fields are used in a query to produce a report showing information based on the employee and date rage selected. The query is based on a table called tblOccurrence and the fields are called Employee and OccurrenceDate that I am pointing to in my query
This code works and produces a report but when no records are found for the employee and date range selected the report shows #Error. I would like a way to find out if records do not exist and either show on the report no records found instead of #Error or pop a message and do not run the report. I prefer the first option if possible.
Below is the code I have been working on which does not work but maybe can be tweaked. If not I will gladly start over.
Private Sub OK_Click()
On Error GoTo OK_Click_Err
Dim stDocName As String
Dim stLinkCriteria As String
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[Employee] = '" & Me![cboEmployee] & "'"
Me.Bookmark = rs.Bookmark
stDocName = "frmOccurrence"
stLinkCriteria = "[EMPLOYEE]=" & "'" & Me![Employee] & "'"
If rs.NoMatch Then
MsgBox "No Records Found"
Exit Sub
Else
DoCmd.OpenReport "Employee Occurrence Summary", acViewPreview, "", "", acNormal
DoCmd.Close acForm, "frmSelectOccurrenceEmploy
ee"
DoCmd.Maximize
Beep
MsgBox "Only Active Employees Displayed", vbInformation, "Information"
Beep
MsgBox "To Print Press (CTRL + P)", vbInformation, "Information"
End If
OK_Click_Exit:
Exit Sub
OK_Click_Err:
MsgBox Error$
Resume OK_Click_Exit
End Sub
Start Free Trial