Hi.
I'm trying to use DLookup to check wheter a specific date value is present in a table or not.
The date to search for is stored in the variable datadate. The value of datadate i set by pulling the max value of a date field in a temporary table.
The table i want to search in is Holdings and the field I want to serch in is Date. Thus my DLookup syntax is
Dim datadate as Date
datadate = DMax("DATE", tablename & "_temp")
If IsNull(DLookup("[DATE]", "Holdings", "[DATE] = #" & datadate & "#")) Then
However when i try to run the sub i get an error message saying that there is a syntax error in the date in the expression . What I find strange is that VBA recognizes datadate as a date variable (IsDate(datadate)=true), for wich the value is 24.02.2011 (norwegian local date format). If i try passing the date by harcoding the date into the DLookup function using the format MM/DD/YYYY the value is accepted as a date.
Can anybody see whats wrong with my syntax or know of a way to work around the issue of different local formats?
Any help would be appreciated
I'm trying to use DLookup to check wheter a specific date value is present in a table or not.
The date to search for is stored in the variable datadate. The value of datadate i set by pulling the max value of a date field in a temporary table.
The table i want to search in is Holdings and the field I want to serch in is Date. Thus my DLookup syntax is
Dim datadate as Date
datadate = DMax("DATE", tablename & "_temp")
If IsNull(DLookup("[DATE]", "Holdings", "[DATE] = #" & datadate & "#")) Then
However when i try to run the sub i get an error message saying that there is a syntax error in the date in the expression . What I find strange is that VBA recognizes datadate as a date variable (IsDate(datadate)=true), for wich the value is 24.02.2011 (norwegian local date format). If i try passing the date by harcoding the date into the DLookup function using the format MM/DD/YYYY the value is accepted as a date.
Can anybody see whats wrong with my syntax or know of a way to work around the issue of different local formats?
Any help would be appreciated