Text Boxes - After Update, Lost Focus or What?? (1 Viewer)

HL

Registered User.
Local time
Today, 15:38
Joined
Feb 13, 2001
Messages
19
Can anyone please help!!!!!

I have a form where I have a text box called "Birthdate"

Then another text box called "age".

I am using this code

Dim dbs As Database
Dim rst As Recordset
Dim lngdays As Long
Dim dblYears As Double
Dim datBirthdate As Date
Dim intage As Integer
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("age", dbOpenDynaset)
With rst
Do While Not .EOF

datBirthdate = ![Birthdate]
lngdays = DateDiff("d", datBirthdate, Now())
dblYears = lngdays / 365
intage = Int(dblYears)

.Edit
![age] = intage
.Update
.MoveNext
Loop
.Close
End With

The problem that I have is when I enter the birthdate in on the form nothing appears in the age text box.

The information only appears when the form is loaded as set up in the properties.

What I would like to happen is when I have finished entering the birthdate the information will appear straight away in the age text box.

Any clues where I put this event procedure????

Cheers

HL
 

AlanS

Registered User.
Local time
Today, 10:38
Joined
Mar 23, 2001
Messages
292
The code you're using loops through the recordset and updates the [age] field in each record, but doesn't do anything to the form itself (as far as I can see). To update the [age] text box when a new value is entered in the [Birthdate] text box, put this code into the AfterUpdate procedure for [Birthdate]:

[age] = Int(DateDiff("yyyy", DateValue([Birthdate]), Now()))

You may also want to reconsider storing the age in your table, since to maintain accuracy its value must be recalculated for every record in the table every time there is a change in the system date (or such other date you may be using as a reference). By removing that field from the table, you would obviate the need for your existing code and the overhead of running it every day, while still having the current age display and update on your form.
 

Users who are viewing this thread

Top Bottom