Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dlookup

Status
Not open for further replies.

mikeba1

Programmer
Jan 2, 2005
235
GB
Having a problem with above.
I am developing a diary system that arranges appointments.
I need to identify if a particular set of dates have a bank holiday within them.
I tried the attached code but it works fine on the second date which is a bank holiday, but fails on the next date which is also a bank holiday

Private Sub Command6_Click()
' loop through a set of dates to determine if they are bank holidays
Dim dloop As Date
Dim k, sqldate, bh
dloop = "14/07/14"
For k = 1 To 6
sqldate = Format$([dloop], "\#dd\/mm\/yyyy\#")
MsgBox (dloop)
bh = DLookup("[bhdate]", "bankholidays", "[bhdate] = " & sqldate & "")
If IsNull(bh) Then
MsgBox ("date not found on bank holidays")
Else
MsgBox ("date FOUND on bank holidays")
End If
dloop = dloop + (6 * 7) ' update in 6 weeks time
Next k
End Sub


Table bankholidays
bhdate Date/Time primary key
bhname Text


data on table bankholidays
bhdate bhname
25/08/14 Summer Bank Holiday
06/10/14 test
25/12/14 Christmas
 
Replace this:
sqldate = Format$([dloop], "\#dd\/mm\/yyyy\#")
with this:
sqldate = Format$(dloop, "\#yyyy-mm-dd\#")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PH, works fine.
I get confused as the correct format to use at times.
Grey cells falling out the back of the head.

Thanks once again
 
Allen Browne, who lives 'down under,' and hence uses non-US date formats, has an excellent article on the subject that is worth bookmarking:

International Dates in Access

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top