How to pass date variable in DLookup in VBA?
Very simple question. I am asking the user to input date. I am using the
month of that date to look up month name (5 for may, 6 for june, etc). I
have a ref table called months with month_id and month_name (1-enero,
2-febrero, etc) in Spanish. I am writing this in VBA:
Dim FileDate as Date
Dim DateString as String
DateString = InputBox("Enter the file date in MM/DD/YYYY format", "Title")
FileDate = DateValue(DateString)
monthname = DLookup("[month_name]", "[months]",
"Format(Month(FileDate),'0') = [month_id]")
But this is giving me errors. If I use Date() instead of FileDate, it is
working correctly. Am I passing the variable incorrectly?
No comments:
Post a Comment