I've been stumped for the past couple of days trying to discern a method for a form to determine that it's a new month and run a procedure and only run it on month change.
My initial thought is:
Open recordset
move to the last record
compare the month in a date field within the last record to the current month
and run the procedure if the month is different.
I can't get this to work however and I'm not sure what I'm doing wrong. To be honest I typically fumble my way through VBA when it comes to opening recordsets. Here's what I got:
txtReqNumb and txtFltNumb are the values to be reset at the beginning of each month.
Am I on the right track and just have the VBA wrong? Is there an easier way to go about this?
Thanks for the help!
My initial thought is:
Open recordset
move to the last record
compare the month in a date field within the last record to the current month
and run the procedure if the month is different.
I can't get this to work however and I'm not sure what I'm doing wrong. To be honest I typically fumble my way through VBA when it comes to opening recordsets. Here's what I got:
Code:
Dim rs As DAO.Recordset
Dim db as CurrentDB
Dim strSQL As String
Set rs = CurrentDB.OpenRecordset("FlightLog")
strSQL = SELECT [txtDate] FROM [FlightLog]
If rs.Recordcount <> 0 Then
rs.MoveLast
End If
If strSQL < Now() Then 'Or Me.txtSysDate which is a textbox on
' the form with a system short date
Me.txtReqNumb = 0
Me.txtFltNumb = 0
End If
txtReqNumb and txtFltNumb are the values to be reset at the beginning of each month.
Am I on the right track and just have the VBA wrong? Is there an easier way to go about this?
Thanks for the help!