Hi,
Hoping someone can assist with this one that has been bugging me.
I have a form on which the user enters a date range before executing a query and showing a report. I have added VBA to ensure the user enters the start date and finish date as well as checking the start date is before the finish date etc., plus a couple of buttons that toggle the dates in the start and finish date to the current and previous financial year.
This is all good to this point, except when the user manually enters the date, then my VBA kicks in a stops me in my tracks. See code below. Any help is appreciated.
Hoping someone can assist with this one that has been bugging me.
I have a form on which the user enters a date range before executing a query and showing a report. I have added VBA to ensure the user enters the start date and finish date as well as checking the start date is before the finish date etc., plus a couple of buttons that toggle the dates in the start and finish date to the current and previous financial year.
This is all good to this point, except when the user manually enters the date, then my VBA kicks in a stops me in my tracks. See code below. Any help is appreciated.
Code:
Private Sub cmdExpReport_Click()
If IsNull(ExpStartDate) Then
MsgBox "Please enter a start date.", vbOKOnly, "Expenses Report"
ExpStartDate.SetFocus
ElseIf IsNull(ExpFinishDate) Then
MsgBox "Please enter a finish date.", vbOKOnly, "Expenses Report"
ExpFinishDate.SetFocus
ElseIf ExpStartDate > ExpFinishDate Then
MsgBox "Please check the dates - the start date must be on or before the finish date.", vbOKOnly, "Expenses Report"
ExpStartDate.SetFocus
ElseIf DCount("*", "ExpensesQuery") = 0 Then
MsgBox "No records found.", vbOKOnly, "Expenses Report"
ExpStartDate.SetFocus
Else: DoCmd.OpenReport "ExpensesReport", acViewPreview, , , acDialog
End If
End Sub
Private Sub cmdExpCurrentFY_Click()
ExpStartDate = IIf(Date < "01/07/" & (Year(Date)), "01/07/" & (Year(Date)), "01/07/" & (Year(Date) + 1))
ExpFinishDate = IIf(Date < "01/07/" & (Year(Date)), "30/06/" & (Year(Date) + 1), "30/06/" & (Year(Date)))
cmdExpPreviousFY.Enabled = True
cmdExpCurrentFY.Enabled = False
cmdExpPreviousFY.SetFocus
End Sub
Private Sub cmdExpPreviousFY_Click()
ExpStartDate = IIf(Date < "01/07/" & (Year(Date)), "01/07/" & (Year(Date) - 1), "01/07/" & (Year(Date)))
ExpFinishDate = IIf(Date < "01/07/" & (Year(Date)), "30/06/" & (Year(Date)), "30/06/" & (Year(Date)))
cmdExpPreviousFY.Enabled = False
cmdExpCurrentFY.Enabled = True
cmdExpCurrentFY.SetFocus
End Sub
Last edited: