date syntax problem

richard luft

Registered User.
Local time
Today, 07:11
Joined
Jun 4, 2004
Messages
63
Hi; I'm using the following code in Ac2 without problem, but Ac2K is not recognizing 'd' as date. Can someone suggest the corrected syntax?
>>>>>>>
Function LenMonth(d)

Start = DateValue(month(d) & " / 1 / " & year(d))
Finish = DateAdd("m", 1, Start)
LenMonth = Finish - Start
End Function
 
Try declaring the d as a date variable in the function header. That should do the trick, you'll have to make sure you're sending a date variable to the function of course:

Function LenMonth(d as Date)
Start = DateValue(month(d) & " / 1 / " & year(d))
Finish = DateAdd("m", 1, Start)
LenMonth = Finish - Start
End Function

Hope that works.

-Chappy
 
unfortuneately, that gives an "By Ref Argument Type Mismatch" with the calling function, which is:
>>>>>>>
Private Function Cal(m, y)
Dim F As Form, C As Control
Set F = Forms![Calendar]


For k = 0 To 41
F("Button" & k).Visible = False
Next

DayOne = DateValue(m & "/1/" & y)
offset = Weekday(DayOne) - 2

For k = 1 To LenMonth(DayOne)
Set C = F("Button" & k + offset)
C.Visible = True
C.Caption = k
Next

End Function

Private Sub CalDate_Change()
Me![FormSchedule].Form![cboDate] = Me![CalDate]
End Sub
>>>>>>>
Hoping that someone can solve this for me.
Richard
 
In the Function Cal, make sure to declare the DayOne variable as a date variable, that should stop the ByRef error.

Hope that helps.

-Chappy
 
yes, it stops the ByRef error, but it again generates the Type Mismatch error at the line :
start = DateValue(month(D) & "/1/" & year(D)) in the LenMonth function.
Richard
 
Just a guess, Richard.

Function LenMonth(byval d as variant)

Regards,
Tim
 
Discovered that 'type mismatch' disappears when month and year are given NO arguments in Start.

Problem solved.
Richard
 

Users who are viewing this thread

Back
Top Bottom