MS Access 2000 Automatic Data Entry in Form
Category: Computers > Software
Asked by: sjkistler-ga
List Price: $10.00
12 Feb 2003 07:37 PST
Expires: 14 Mar 2003 07:37 PST
Question ID: 160428
Using MS Access 2000, I have three fields of interest on a form: 1. Membership 2. Begin Date 3. End date We currently enter all three fields by hand - the first with an number, the second and third with dates. I want to set it up so that when a number is entered into membership it represents the number of annual memberships. If a 1 is entered the Begin Date would automatically enter the current date and the End Date would automatically enter 1 year from now. If a 1.5 is entered the Begin Date would automatically enter the current date and the End Date would automatically enter 18 months from now. This all must be done within the form. How?
Re: MS Access 2000 Automatic Data Entry in Form
Answered By: hammer-ga on 12 Feb 2003 08:09 PST
The example code below is based on a form which has three text boxes: 1. txtMembership 2. txtBeginDate 3. txtEndDate txtBeginDate and txtEndDate are both formatted as "Short Date", but you can use whatever date format suits you. I put the example on the OnExit event of txtMembership, but you can move it to whichever event makes sense for your application. Private Sub txtMembership_Exit(Cancel As Integer) ' Declare two date variables Dim datBeginDate As Date Dim datEndDate As Date ' If txtMembership contains one of the specified values ' calculate the dates, otherwise, clear the date fields. If txtMembership = "1" Then datBeginDate = Now() datEndDate = DateAdd("yyyy", 1, datBeginDate) txtBeginDate = datBeginDate txtEndDate = datEndDate ElseIf txtMembership = "1.5" Then datBeginDate = Now() datEndDate = DateAdd("m", 18, datBeginDate) txtBeginDate = datBeginDate txtEndDate = datEndDate Else txtBeginDate = "" txtEndDate = "" End If End Sub Note: The Now() function returns the system date and time. Note: I have used the DateAdd function to perform both calculations. Additonal Resources: Look at the Now() and DateAdd functions in the Access 2000 online Help. MVPS Access FAQ Date Section http://www.mvps.org/access/datetime/index.html Good luck with your Access project! - Hammer
rated this answer:
Well done - responded and refined answer to meet my specs. Thanks.
|There are no comments at this time.|
If you feel that you have found inappropriate content, please let us know by emailing us at email@example.com with the question ID listed above. Thank you.
|Search Google Answers for|