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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need a label on a form that displays the difference between 2 dates,

Status
Not open for further replies.

mjbuk

Technical User
Mar 19, 2001
1
GB
I am trying to make a form that tells the user how many days they have until a certain date.

This is what I have done so far:-

Private Sub txtInstallDate_AfterUpdate()

Me.txtToday.Value = Now()

Me.txtWhen = DateDiff("d", Me.txtToday, Me.txtInstallDate, vbMonday, vbFirstJan1) & " Working days until " & Me.txtRouterID & " " & Me.txtEdgeID & " are Installed at " & Me.txtSiteIndex & "- " & Me.txtSiteName

End Sub

This works. The text box tells the user how many days until the install date.

How do I get the text box to change and do the relevant calculation for the current record, as I move through the records, because at the moment it only displays the message for the last record I updated.
 
try putting:

txtInstallDate_AfterUpdate

in the form's current event. You can change the value in an existing record or see the calculation when you move to a new record.
 
Move your code to the controlsource of each unbound control respectively. Then as the control values change that these controls use they will automatically change whith them. For example, in the txtToday controlsource use:
= Now()

and in the txtWhen controlsource use:
= DateDiff("d", txtToday, txtInstallDate, vbMonday, vbFirstJan1) & " Working days until " & txtRouterID & " " & txtEdgeID & " are Installed at " & txtSiteIndex & "- " & txtSiteName

note: you cannot use the Me object in the controlsource property. If you need to reference the form you'll have to use the full path to the form.

= DateDiff("d", Forms!FormName!txtToday, ...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top