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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Do Loop problem with Dates

Status
Not open for further replies.

stupiet

Programmer
Aug 21, 2001
176
US
To whomever can help me,

I am building a work calendar and want to block out the holidays. I created a ListHoliday Table, in which I have listed all holidays for the year in the column called HOLIDAY. Now in my calendar I want that day blocked out (invisible). However, in my Do Loop somehow it's not doing it. I think it's because my format is not correct. I'm thinking it's an easy fix, but since I'm new to VB I got stuck. Please help! Below is my code ("workdate" is the current date on the calendar):

sqlhol = "SELECT * FROM ListHolidays;"
Set dbhol = CurrentDb()
Set rshol = dbhol.OpenRecordset(sqlhol, dbOpenSnapshot)

Do Until rshol.EOF
If workdate = rshol!HOLIDAY Then
f("TextboxA").Visible = False
f("TextboxB").Visible = False
Else
f("TextboxA").Visible = True
f("TextBoxB").Visible = True
End If
rshol.MoveNext
Loop
rshol.Close
dbhol.Close
 
Might help to check to make sure your comparing like with like...

...
if datevalue(workdate) = datevalue(format(rshol!HOLIDAY, "General Date")) then
...

Using datevalue() has the advantage of ignoring any time values that may be included in your tables date field(s)
 
What does f("TextboxA").Visible mean?
I don't understand why you are looping. The visible setting will reflect the last record only.
 
You're right. My looping is not doing what I want it to do. Instead I used Dlookup to match the day with the holiday and seems to work fine. Only thing using DLookup makes the form a little slow. Is there anything i can do to speed it up?

TextboxA is a textbox on a form that will be visible on workdays only. On Holidays textboxA is invisible.

This is what I did:

Set f = Forms!frmCalender

For a = 1 To 31
f("Day" & a ).Visible = True

If IsNull(DLookup("HOLIDAY", "ListHolidays", "HOLIDAY=#" & workdate & "#")) Then
f("TextboxA" & a).Visible = True
Else
f("TextboxA" & a).Visible = False
End If

workdate = workdate + 1
f("Day" & a) = a

Next
 
I think dlookup is terribly slow. You could try combining both your bits of code.
Loop through the recordset as you have in the first bit of code and set the visible like in the second.
If the holiday table just contains holidays, set the boxes all visible and clear the matching ones from the table. The value from the table is the holiday day number ? so you could use that to clear the appropriate textbox visible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top