Formula in a Macro

J

Johnny

I would like to create an If statement in a macro to subtract one date from
another date located on my form and if the result is greater then 3, a
userform (which I already created) pops up prompting a few questions. The
two dates are located on a form in the text fields as Text19 and Text20.

I haven't got a clue on how to incorporate a forumla in a macro let alone
subtract two dates to determine if the numerical value is greater than 3.

Thanks.
 
G

Greg Maxey

Subject to some possible error handling, this might get you on track:

Sub OnExitTxt20()
Dim dtg1 As Date
Dim dtg2 As Date
Dim oBMs As Bookmarks
Dim dtgDiff As Long
Set oBMs = ActiveDocument.Bookmarks
dtg1 = oBMs("Text19").Range.FormFields(1).Result
dtg2 = oBMs("Text20").Range.FormFields(1).Result
If IsDate(dtg1) And IsDate(dtg2) Then
dtgDiff = CLng(DateDiff("d", dtg1, dtg2))
End If
If dtgDiff > 3 Then
'Fire your UserForm
End If
End Sub
 

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