No, not a filter. The query in the code (the strSQL) is an update query. It selects all records to be updated with the date.
If you want only selected records, you can add criteria. The SQL that uses criteria is commented out. Uncomment the SQL with criteria and comment out the SQL without criteria.
Could I also modify to use as a 30 day, 90 day, 365 day
You can change the number of days to add.
7 is hard coded in the DateAdd() function. You can use "Select Case" to dynamically change the number or days.
Would I have to a If Statement for every record on my main form to check is it was a daily, weekly, monthly, quarterly or yearly event and then run code?
Probably... but I would use "Select Case" syntax, not an If() statement.
Also, the code example was to show how to add 7 days to a date. I'm still not sure of what you are trying to do. Or when you want it to happen. If it is called in a Form_Current event, the code would try to update records in tblmissedtransactions EVERY time the current record changed. You might also have to add arguments. For example
It would look something like:
Code:
Public Sub CalcNewDate(pEventID As Long, pPeriodType As String)
'Purpose: Find Dates in Increments of 7 Using EventStart Field in tblmissedtransactions.
'Check if date is in field dteentered and if so, increment 7 days from there.
'Starting date was EventStart, next date entered is dteentered.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim TheInterval As String
Dim TimePeriod As Integer
Dim StartDate As Date
Dim NewDate As Date
Set db = CurrentDb()
'Get the date
Set rs = db.OpenRecordset("tblmissedtransactions")
If rs.BOF And rs.EOF Then
MsgBox "No records"
Else
StartDate = rs!EventStart
Select Case pPeriodType
Case "d"
TheInterval = "D"
TimePeriod = 7
Case "M"
TheInterval = "M"
TimePeriod = 30
Case "WW"
TheInterval = "WW"
TimePeriod = 1
Case "Q"
TheInterval = "Q"
TimePeriod = 1
Case "YYYY"
TheInterval = "YYYY"
TimePeriod = 1
End Select
'Calc the new date
NewDate = DateAdd(TheInterval, TimePeriod, StartDate)
'Update EventDate - With criteria
strSQL = "UPDATE tblmissedtransactions SET tblmissedtransactions.dteentered = #" & NewDate & "#"
strSQL = strSQL & " WHERE tblmissedtransactions.dteentered = " & pEventID & " ;"
'Update EventDate - all records
' strSQL = "UPDATE tblmissedtransactions SET tblmissedtransactions.dteentered = #" & byseven & "#;"
'update EventDate
db.Execute strSQL, dbFailOnError
End If
'clean up
rs.Close
Set rs = Nothing
End Sub
You would call this function using
Call CalcNewDate(EventID, PeriodTypeID)
PeriodTypeID should be a string = "D, "M", "WW", "Q" or "YYYY"
Still not really sure what you are trying to do.....