I am trying to check if the current date is between 2 other dates and I can't figure out a way to write an expression. For example I want to know if today's date (7/20/2010) is in between 7/19/2010 and 7/26/2010 ... Here's what I have below:
I have 4 variables and a sql statement that I pull the field [BeginWeek] which is a date field.: myStart and myEnd
I have 4 variables and a sql statement that I pull the field [BeginWeek] which is a date field.: myStart and myEnd
Code:
Dim curDate as Date
Dim rst As Recordset
Dim db As Database
Dim sql As String
Dim myEnd, myStart As Date
sql = "SELECT tblOnCallTable.[B]BeginWeek[/B], tblOnCallTable.Personnel, tblOnCallTable.[Home#], tblOnCallTable.[Cell#] " _
& "FROM tblOnCallTable;"
Set db = CurrentDb
Set rst = db.OpenRecordset(sql)
rst.movefirst
myStart = Format(rst![BeginWeek], "mm/dd/yyyy") & " 17:00"9/19/2010 5:00:00 PM
'I add 7 days to myStart
myEnd = DateAdd("d", 7, Format(rst![BeginWeekDay], "mm/dd/yyyy")) & " 07:00"
curDate = Format(Now, "mm/dd/yyyy hh:nn")
myStart = Format(rst!BeginWeekDay, "mm/dd/yyyy") & " 17:00"
If curDate >= myStart And curDate <= myEnd Then
onCallPerson = rst!personnel & " - Cell: " & rst![Cell#] & " Home: " & rst![Home#]
Else
End If
debug.print onCallPerson