General discussion

Locked

Using DateAdd function to display a date

By spursi ·
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 ????

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Using DateAdd function to display a date

by SteveD In reply to Using DateAdd function to ...

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

Collapse -

Using DateAdd function to display a date

by spursi In reply to Using DateAdd function to ...

Poster rated this answer

Collapse -

Using DateAdd function to display a date

by roc180 In reply to Using DateAdd function to ...

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

Collapse -

Using DateAdd function to display a date

by spursi In reply to Using DateAdd function to ...

Poster rated this answer

Collapse -

Using DateAdd function to display a date

by spursi In reply to Using DateAdd function to ...

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

Collapse -

Using DateAdd function to display a date

by spursi In reply to Using DateAdd function to ...

This question was closed by the author

Back to Web Development Forum
6 total posts (Page 1 of 1)  

Related Discussions

Software Forums