Calendar Form-Dlookup not working

F

Frank Stone

I have created a calendar form that on open shows the
current month. Code populates 42 text boxes with the days
in the correct day columns. By pressing the Page up key,
the form calulates and displays the next month. I have ran
it up to 2050. By pressing the page down key, the form
displays last month.
My problem is I now want to color our holidays red using
the DLookup function. I have created a table with all of
our holidays. The DLookup function looks for a match in
the table with a date in a hidden text box(txtD1) on the
form. txtD1 is what the code uses to know what day number
to put in each of the 42 text boxes.(using the datepart
function to reduce a date like 8/1/04 to the number 1.)
Code then adds 1 to txtD1 then loops. next text box.
try as I may I can not get the DLookup function to match
anything. I have used it before with success. I've made
sure the table is formated to short date and txtD1 is
formated to short date. Here is the what I've written:

Sub NewDates()
Dim D1 As Variant, D2 As Integer, D3 As Integer
Dim stgSQL As String
Me![scrMonth] = Format(Me![scrCDate], "mmmm")
Me![scrYear] = Format(Me![scrCDate], "yyyy")
D1 = DateSerial(Year(Me![scrCDate]), Month(Me![scrCDate]),
1)
D2 = DatePart("w", D1, vbMonday)
Do Until DatePart("w", D1, vbSunday) = 1
D1 = DateAdd("d", -1, D1)
Loop
Me![scr1Date] = D1
D3 = 1
Do Until D3 > 42
Me("C" & Format(D3, "00")) = Day(D1)
If Month(D1) <> Month(Me![scrCDate]) Then
Me("C" & Format(D3, "00")).ForeColor = 8421504
Me("C" & Format(D3, "00")).FontWeight = 400
Else
Me("C" & Format(D3, "00")).ForeColor = 0
Me("C" & Format(D3, "00")).FontWeight = 700
End If
If (DLookup
("[HDate]", "tblCalendarHolidays", "[HDate]" = Me.
[txtD1])) Then
Me("C" & Format(D3, "00")).ForeColor = 255
End If
D3 = D3 + 1
D1 = DateAdd("d", 1, D1)
Me.txtD1 = D1
Me.TxtD12.Requery
Loop

Me.Repaint
End sub
What is wrong with DLookup?#*!@
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top