Discussion Locked

Using DateAdd function to display a date

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have created a form that displays the date in one field and I want to display a date in another field that adds 45 days to that date.

I have tried to us the DateAdd function but I have been unsuccessful in writing the expression in the control source for that field. So what must I do ????

6 replies

by steved

You didn't specify your programming environment, but I'll assume Visual Basic from the clues you've provided. Say you have two textboxes, Text1 and Text2. If you want the value of Text2 to change when the user inputs a value in Text1, try putting something like this code in the LostFocus event of Text1:

Private Sub Text1_LostFocus()
Dim d As Date, e As Date
d = CDate(Text1.Text)
e = DateAdd("d", 45, d)
Text2.Text = CStr(e)
End Sub

(Of course, this doesn't include error checking.)

When the user tabs away from the Text1 box, the new value will appear in Text2.

I hope this helps.

Steve Diamond

by roc180

First are you sure you have the syntax right for the date add and setting the text box control. It should look something like this:

Private Sub Form_Open()
Txt1.Text=Date()
Txt2.Text=DateAdd("d", 45, date())
End Sub

OR

Private Sub Txt1_LostFocus()
Txt2.Text=DateAdd("d", 45, cDate(Txt1.Text))
End Sub

Good Luck

Neal Martinelli

by spursi

The programming environment,is MS ACCESS97
or should I do this in VB. ( I have VB 5.0 )

This discussion is closed to new replies.