Help! Problem passing Function result to a form

hardrock

Registered User.
Local time
Today, 19:37
Joined
Apr 5, 2007
Messages
166
Hi all, i'm using the code below to try and return the workdays between begdate and enddate. Values get loaded via 2 textboxes on form. The function itself works fine, but i cannot get the calculated Work_days (at bottom of function) to display on a 3rd textbox on my form.

The function is this

-----------------------------------
Function Work_Days(BegDate As Variant, EndDate As Variant) As Integer

' "Calculating the workdays between Dates"
' Note that this function does account for holidays.

Dim WholeWeeks As Variant
Dim DateCnt As Variant
Dim EndDays As Integer

BegDate = DateValue(BegDate)
EndDate = DateValue(EndDate)
DateCnt = BegDate
EndDays = 0

Do While DateCnt <= EndDate

If Not IsNull(DLookup("HoliDate", "tblHolidays", "[HoliDate]=#" & DateCnt & "#")) Then
EndDays = EndDays - 1
End If

If Format(DateCnt, "ddd") <> "Sun" And _
Format(DateCnt, "ddd") <> "Sat" Then
EndDays = EndDays + 1
End If
DateCnt = DateAdd("d", 1, DateCnt)
Loop
Work_Days = EndDays

End Function
---------------------------------------

And my code to get the result on the click of a button on my form is

Private Sub CalcDays_Click()

Call Work_Days(begdate, EndDate) ' Both textbox names
Workd.value = Work_Days

End Sub
------------------------------------------------------
Workd is name of a textbox on my form. I get a compile error that arguments are missing in

Workd.value = Work_Days

Plese anyone, any ideas why i am getting this error?

zip file of db is attached. Thanks
 

Attachments

Change this:
Call Work_Days(begdate, EndDate) ' Both textbox names
Workd.value = Work_Days

to this:
Workd = Work_Days(begdate, EndDate)


And as an FYI, you don't need Workd.Value as .Value is the default for text box controls.
 
Thankyou

Thankyou bob! i really was pulling my hair out on that one!
 

Users who are viewing this thread

Back
Top Bottom