W
wrightlife11
I am trying to use a date for comparison in a do while loop. The Loop works
great! No problems there.... but I need to find out what is wrong with the
dlookup I am tring to use. It always returns null. causing the rest of the
function to bomb.
Any Ideas?
Option Compare Database
Option Explicit
Public Function WorkDaysAdj() As Variant
'Required Inputs:StartDate As Date, AdjDays As Integer
'....................................................................
On Error GoTo Err_WorkDaysAdj
Dim AdjDays As Integer
Dim StartDate As Variant
Dim NewDate As Variant
Dim HDay As Variant
StartDate = #9/1/2008#
AdjDays = 12
NewDate = StartDate
'I tried to do a DLookUp that looked like this but got an error "invalid use
of null"
HDay = DLookup("[Holiday]", "tblHolidays", "[Holiday]=" & NewDate)
Debug.Print HDay & " Holiday"
' Here I tried to keep the DLookUp from returnging a null.
HDay = IIf(DLookup("[Holiday]", "tblHolidays", "[Holiday]=" & NewDate) <
#1/1/2001#, #1/1/2001#, DLookup("[Holiday]", "tblHolidays", "[Holiday]=" &
NewDate))
Debug.Print HDay & " Holiday"
Exit_WorkDaysAdj:
Exit Function
Err_WorkDaysAdj:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkDaysAdj
End Select
End Function
great! No problems there.... but I need to find out what is wrong with the
dlookup I am tring to use. It always returns null. causing the rest of the
function to bomb.
Any Ideas?
Option Compare Database
Option Explicit
Public Function WorkDaysAdj() As Variant
'Required Inputs:StartDate As Date, AdjDays As Integer
'....................................................................
On Error GoTo Err_WorkDaysAdj
Dim AdjDays As Integer
Dim StartDate As Variant
Dim NewDate As Variant
Dim HDay As Variant
StartDate = #9/1/2008#
AdjDays = 12
NewDate = StartDate
'I tried to do a DLookUp that looked like this but got an error "invalid use
of null"
HDay = DLookup("[Holiday]", "tblHolidays", "[Holiday]=" & NewDate)
Debug.Print HDay & " Holiday"
' Here I tried to keep the DLookUp from returnging a null.
HDay = IIf(DLookup("[Holiday]", "tblHolidays", "[Holiday]=" & NewDate) <
#1/1/2001#, #1/1/2001#, DLookup("[Holiday]", "tblHolidays", "[Holiday]=" &
NewDate))
Debug.Print HDay & " Holiday"
Exit_WorkDaysAdj:
Exit Function
Err_WorkDaysAdj:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkDaysAdj
End Select
End Function