Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff Issue

Status
Not open for further replies.

davidmo

Technical User
Apr 8, 2003
97
US
Hey everyone:
I am trying to use a DateDiff to have another field become true/false. It compares the employees start date verse today's date. If it is less than 24 months than the field becomes true, if it is greater 24 months than the field is false.

But it is not working. Any thoughts on what to do. Here is the code.

Private Sub Borrower_Current_Employer_Start_Date_AfterUpdate()
Dim dtEmploy As Date
Dim intTwoYears As Integer

dtEmploy = Me.Borrower_Current_Employer_Start_Date

intTwoYears = DateDiff("m", dtEmploy, Date)

If intTwoYears < 24 Then
frm_Employment_History.Visible = True
Else
frm_Employment_History.Visible = False
End If
End Sub
 
Modify your form so a text box (hidden) is showing the result of the date difference, then run the subform visibility from that. Here's my code that worked in my design copy:

I added a text box called TestDateDiff, which shows my date difference value when I update the Employer_Start_Date field.

Private Sub Borrower_Current_Employer_Start_Date_AfterUpdate()

TestDateDiff.Value = DateDiff("m", [Borrower_Current_Employer_Start_Date], Date)

If [TestDateDiff] < 24 Then
frm_Employment_History.Visible = True
Else
frm_Employment_History.Visible = False
End If
End Sub
 
Hi, davidmo,

Have you tried stepping through the code? Where does it break? What values do your variables hold as you step through?

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top