Date syntax error

time4d

New member
Local time
Yesterday, 16:54
Joined
Jan 4, 2010
Messages
3
I am needing to do the following...

Code:
vr_Month = MonthNumber(txt_MonthName)
vr_Date_Selected = DateSerial(Me!txt_Year, vr_Month, Me!Text8)

rst.MoveFirst
    Do Until rst.EOF
       If rst!f_date = # & vr_Date_Selected & # Then
           ---Do something ---          
       End If
            
    rst.MoveNext
    Loop

I can't get the vr_Date_Selected to match the rst!f_date.
I've tried all the '"# & vr_Date_Selected & # "' combinations I can think of but still couldn't get it to work... If I do rst!f_date = #1/3/2010# it works without a problem...

Please help...

Thanks :D
 
Did you think about the change of year (2009, 2010).
 
It's enough to declare the variable as a date data type ...
Code:
dim vr_date as date
Once that's done you don't need the literal date delimiters '#' in a boolean comparison. VBA will know it's a date.
But I would add that criteria in the WHERE clause of the recordset. That way all records will satisfy the criteria and there's no need for the conditional branch inside the loop.
And if you need a recordset for other purposes, open a different one.
 

Users who are viewing this thread

Back
Top Bottom