Hi,
Trying to check if a date is between 2 dates. The code below shows the various attempts to make this work. I can't get it to work when I use variables for the dates. Worked hours in trying to figure this out.
Karen

Sub testDateCheck()

Dim dateOpen As Date
Dim dateClose As Date
Dim tDate As Date

dateOpen = #7/1/2021#
dateClose = #9/30/2021#
tDate = #8/22/2021#

MsgBox "dateOpen is " & dateOpen
MsgBox "dateCLose is " & dateClose
MsgBox "tDate is " & tDate
    
'This works - results in open
            If #8/22/2021# >= #7/1/2021# And #8/22/2021# <= #9/30/2021# Then
                MsgBox "Open"
            Else
                MsgBox "Close"
            End If
    
'This doesn't work - results in close
            If " & tDate & " >= " & openDate & " And " & tDate & " <= " & closeDate & " Then
                MsgBox "Budget Open variable"
            Else
                MsgBox "budget closed variable - try 1"
            End If

'This doesn't work - results in close
            If tDate >= openDate And tDate <= closeDate Then
                MsgBox "Budget Open variable"
            Else
                MsgBox "budget closed variable - try 2"
            End If
            
'This doesn't work - results in close
            If "#" & tDate & "#" >= "#" & openDate & "#" And "#" & tDate & "#" <= "#" & closeDate & "#" Then
                MsgBox "Budget Open variable"
            Else
                MsgBox "budget closed variable - try 3"
            End If
            
End Sub