-
Autofill form fields
Ok i am also new to Access and form programming. Here is what i want to setup.
I have four fields on a form, Staff Last Name, Staff First Name, Vehicle Owner Last Name, Vehicle Owner First Name.
I want to have code that does the following.
On Vehicle Owner Last Name Focus if it is blank autofill it with Staff Last Name.
On Vehicle Owner First Name Focus if it is blank autofill it with Staff First Name.
What would be my code to accomplish such a task? Thank you so much in adavance.
-
I prefer to use the On Enter event.
I would use code like this:
Code:
Private Sub VehicleOwnerLastName_Enter()
If IsNull(Me.VehicleOwnerLastName) then
Me.VehicleOwnerLastName = Me.StaffLastName
End If
End Sub
IMHO, you are not following the rules of data normalization. ou are creating repeating data.
I woudl recoment eat you has a people table. You wil look up the Primaryu key form the people table for the the Staff and the Vehicle.
I would have:
Code:
Private Sub VehicleOwnerID_Enter()
If IsNull(Me.VehicleOwnerID) then
Me.VehicleOwnerID = Me.StaffID
End If
End Sub
AN even better design would use a child tbale with one record per person with a field for the type (staff, owner) and People ID.