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

Can someone tell me what this VB code does?

Status
Not open for further replies.

NeoZakz

Technical User
Jul 22, 2002
25
0
0
US
Im fixing a database and this is the only thing I cant figure out. Its supposedly code to take a number of days change +/- and then recalculate the date's due for any documents with the same milestone number. Any ideas on how to do that or what this actually does would be appreciated.



Private Sub days_after_Change()
If Me![days after] Is Not Null Then Me![Date Due] = DateAdd("d", Me![days after], Me![miledate])

End Sub




Thanks.
 
The code looks fine.

DateAdd is a built-in function in Access you can surely check it out it in Access Help.

The code is for calculating the [Due Date]. The formula is:

[Due Date]= [MileDate] + [Days After]


seaport
 
This code runs if the days after field on the current form is changed by the user.

If the days after field (on the current form) has a value in it then add that value as a number of days to the date in the miledate field (on the current form) and store the answer in the datedue field (on the current form).

If the form has been bound to a table then the corresponding fields in the table will be updated for the record shown on the form.

If the days after field does not have a value then no change is made.

Normally I would have the code running when that field is updated using the AfterUpdate event not the Change event. The code would be the same except the first line would be

Private Sub days_after_AfterUpdate()

The problem with your code is that I would expect it to run as each single character changes. So you type a 3 and the code adds 3 days; you then type a zero after the 3 (to make it 30) and it fires again to add 30 days. This is most confusing for the user. Better to let the user finish typing and action the completed result with the AfterUpdate event.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top