Following is a copy of my post to this thread in the
queries group:
Hi guys,
Hope you don't mind if I join in. In looking at the past
posts I was wondering if the problem may lie with the #
sign date delimiters in the Dlookup function. These are
needed if the criteria is being specified as a date
literal string, but I don't believe it is needed if the
date is being specified as a number representing the date
value.
I actually can't remember off hand how the VBA date data
type provides the values (as a string literal or as the
date value), but I would have expected it to represent
the value. If so, this could be the problem.
Not sure if this will help, but thought I would offer it.
-Ted Allen
>-----Original Message-----
>Thanks but that doesn't work either.
>I have found that the following does work but I don't
know why
>could you explain?
>
>Dim jetdatefmt As String
> jetdatefmt = "\#mm\/dd\/yyyy\#;;;\N\u\l\l"
>
>blnFound = Nz((DLookup
("HolidayDays", "tblHolidayDates", "[HolidayDays]=" &
>Format$(dtmTemp, jetdatefmt))), False)
>
>Thanks for your help so far
>"Ron Weiner" <(E-Mail Removed)> wrote in
message
>news:(E-Mail Removed)...
>> Try replacing
>>
>> dtmTemp = dtmTemp + intIncrement
>>
>> With
>>
>> dtmTemp = dateadd("d", intIncrement, dtmTemp)
>>
>>
>> Ron W
>> "news.microsoft.com" <(E-Mail Removed)> wrote in
message
>> news:(E-Mail Removed)...
>> > Thanks for this - it will fix the error when there
truely is no record
>but
>> > it is returning null when the date is in the table.
>> > For some reason it seems that when adding 1 to the
dtmTemp date it is
>> > changing the way that it is seeing the date.
>> >
>> > How can I get round this?
>> >
>> > Thanks again for your help
>> > "Ron Weiner" <(E-Mail Removed)> wrote in
message
>> > news:(E-Mail Removed)...
>> > > When DLookup doesn't find the date in
tblHolidayDates it returns a
>null.
>> > If
>> > > blnFound is in fact a Boolean that is where the
error is occurring.
>You
>> > can
>> > > not Assign a Null to a Boolean variable. Try
wrapping your DLookup in
>a
>> > > NZ() like this
>> > >
>> > > blnFound = NZ(DLookup
("HolidayDays", "tblHolidayDates",
>> "[HolidayDays]=#"
>> > &
>> > > dtmTemp & "#")False)
>> > >
>> > > Ron W
>> > >
>> > > "Newbie" <(E-Mail Removed)> wrote in message
>> > > news:u3$(E-Mail Removed)...
>> > > > I am trying to find the next available date that
is not a holiday.
>> > > > The holiday dates are in a table.
>> > > >
>> > > > The code works for the first pass through but
once the date has been
>> > found
>> > > > and 1 has been added to give the next date to
evaluate I get the
>error
>> > > > invalid use of Null.
>> > > > When I hover over the variable a valid date
appears.
>> > > >
>> > > > Here is the code snippet
>> > > >
>> > > > Do
>> > > > blnFound = (DLookup
("HolidayDays", "tblHolidayDates",
>> > > > "[HolidayDays]=#" & dtmTemp & "#")) ' this is
where error occurs
>> > > > If blnFound Then
>> > > > dtmTemp = dtmTemp + intIncrement
>> > > > End If
>> > > > Loop Until Not blnFound
>> > > >
>> > > > In my table I have all the dates from 1st June
to 4th June. If I
>send
>> a
>> > > > date of 1st June blnFound returns true and
dtmTemp is incremented by
>1
>> > to
>> > > > give dtmTemp a value of 2nd June. When trying
to evaluate blnFound
>> for
>> > > the
>> > > > 2nd time the error 94 Invalid Use of Null is
returned.
>> > > >
>> > > > Where am I going wrong?
>> > > > All help greatly appreciated
>> > > >
>> > > >
>> > >
>> > >
>> >
>> >
>>
>>
>
>
>.
>
|