Calling a function

  • Thread starter Thread starter Mandy
  • Start date Start date
M

Mandy

I would like to call a function that calculates the
difference between 2 dates, however I'm new to this and
have no idea how to do it!

The function is called DateDiffW(BegDate, EndDate) and is
from this site.

I would like it to work when the 'Calculate' button has
been clicked. Where do I need to put the code and how do
I call the function itself. I presume it'll be in the
on_click event of the button but really don't know what
to do.

Thanks

Mandy
 
Assume you're doing this from a form (frmName) which
contains three TextBoxes (txtBegDate, txtEndDate, txtDiff)
and a CommandButton (cmdCalculate).

In the OnClick event of cmdCalculate:

' make sure dates have been entered
If IsNull([txtBegDate]) or [txtBegDate]="" Then
MsgBox "Error message here"
txtBegDate.SetFocus
Exit Sub
End If

' Same for txtEndDate

' Otherwise...

' declare variables
Dim dtBeg as Date
Dim dtEnd as Date

dtBeg = [txtBegDate]
dtEnd = [txtEndDate]

' call function to populate field
[txtDiff] = DateDiffW dtBeg, dtEnd

Hope this helps!

Howard Brody
 
Back
Top