Hello
I hope this is an easy one and that I'm just having a momentary relapse of brain cells...
I have the following very simple piece of code:
Public Function BankHol(BHDate As Date) As Boolean
Dim X As Variant
X = DLookup("[BH_Date]", "[T_BankHolidays]", "[BH_Date] = " & "#" & BHDate & "#")
If IsNull(X) Then
BankHol = False
Else
BankHol = True
End If
End Function
The function "should" assess whether a date passed to it is stored in a bank holiday dates table. If it is then it returns true. If not false. The problem is it returns false even if the date IS in the bank holiday dates table. I have tried several ways of putting the criteria in the third part of the DLookup both with and without the #'s. The function actually works in the immeadiate window if I type in the #'s around the date but doesn't if I leave them out. The field in the bank holiday dates table is Date data type and the input mask for data entry in the form is dd/mm/yyyy. The regional settings are set to Short date style dd/mm/yyyy. I have also tried converting the BHDate variable to date by using CDate conversion function but it still doesn't work!! Please help - am I going mad?
Thanks in advance.
Helena
I hope this is an easy one and that I'm just having a momentary relapse of brain cells...
I have the following very simple piece of code:
Public Function BankHol(BHDate As Date) As Boolean
Dim X As Variant
X = DLookup("[BH_Date]", "[T_BankHolidays]", "[BH_Date] = " & "#" & BHDate & "#")
If IsNull(X) Then
BankHol = False
Else
BankHol = True
End If
End Function
The function "should" assess whether a date passed to it is stored in a bank holiday dates table. If it is then it returns true. If not false. The problem is it returns false even if the date IS in the bank holiday dates table. I have tried several ways of putting the criteria in the third part of the DLookup both with and without the #'s. The function actually works in the immeadiate window if I type in the #'s around the date but doesn't if I leave them out. The field in the bank holiday dates table is Date data type and the input mask for data entry in the form is dd/mm/yyyy. The regional settings are set to Short date style dd/mm/yyyy. I have also tried converting the BHDate variable to date by using CDate conversion function but it still doesn't work!! Please help - am I going mad?
Thanks in advance.
Helena