Dim stDocName As String, StrWhere As String
On Error GoTo HandleErr
If Not IsDate(Me.txt_From) Or Not IsDate(Me.txt_To) Then
MsgBox "You must add a beginning and ending date", vbInformation + vbOKOnly, "Invalid dates"
Exit Sub
End If
If Me.txt_From > Me.txt_To Then MsgBox "The Beginning date cannot be later then the end date", vbInformation + vbOKOnly, "Incorrect Dates": Exit Sub
Me.Visible = False
'This has two mods of opersation
If Not IsNothing(Me.OpenArgs) Then
StrWhere = "int([ItemDate]) BETWEEN " & Format(Me![txt_From], "\#" & "mm/dd/yyyy" & "\#") & " AND " & Format(Me![txt_To], "\#" & "mm/dd/yyyy" & "\#")
Select Case Me.OpenArgs
Case 1
DoCmd.OpenReport Me.TxtObjectName, acPreview, , StrWhere
Case 2
DoCmd.OpenReport Me.TxtObjectName, acViewNormal, , StrWhere
End Select
DoCmd.Close acForm, Me.Name
End If
HandleExit:
Exit Sub
HandleErr:
Select Case Err.Number
Case 2501, 2212
Exit Sub 'So as the forms been told to close just exit all good
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
Resume HandleExit
Resume
End Select