Results 1 to 2 of 2

Thread: Autofill form fields

  1. #1
    Join Date
    Aug 2009
    Posts
    1

    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.

  2. #2
    Join Date
    Mar 2006
    Location
    Oklahoma City, OK
    Posts
    184
    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.
    Last edited by HiTechCoach; 09-25-2009 at 09:08 PM.
    Boyd Trimmell aka HiTech Coach
    Microsoft MVP - Access Expert
    [SIGPIC][/SIGPIC]
    Office Programming 25+ years as a Software Developer specializing in:
    Business Process Management
    Accounting/Inventory Control
    Customer Relations Management (CRM)
    Electronic Data Interchange (EDI)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •