Results 1 to 6 of 6
  1. #1
    woodpecker is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    11

    auto fill field on a form when another field is updated

    I am looking for the vba code to auto fill in the county when a zipcode is put into the zipcode field
    I was thinking of a select case
    the form is called frmpeople the fields are zipcode and county
    I am not sure how the syntax is to be written exp:
    Select Case Forms!frmPeople!ZipCode
    Case is = 43611
    County = Lucas


    end Select
    nothing happens

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Do you have a table of zip codes and counties
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    woodpecker is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    11
    yes I do have the table

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    One table or two. I would have expected two tables with a one to many relationship (One county can have many zipcodes).
    Create a combo box on the form to show the zipcodes and counties with the county column hidden. Set the Control Source property of a text box on the form to reference the hidden column of the combo box.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Join Date
    Apr 2017
    Posts
    1,776
    When you want only to display the county in form/report - create an unbound text box and use a formula to display a county (DLookup formula, or Bob's method)

    When you want the county stored in same table (p.e. when you need to filter by county) - create a text box linked to county (code), disable editing for this text box, and set it's value in AfterUpdate event of control, you used to enter the ZIP code. In case you want to store county code, but to display it's name, use combo box instead of text box (but anyway disable editing).

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Quote Originally Posted by ArviLaanemets View Post
    When you want only to display the county in form/report - create an unbound text box and use a formula to display a county (DLookup formula, or Bob's method)

    When you want the county stored in same table (p.e. when you need to filter by county) - create a text box linked to county (code), disable editing for this text box, and set it's value in AfterUpdate event of control, you used to enter the ZIP code. In case you want to store county code, but to display it's name, use combo box instead of text box (but anyway disable editing).
    I believe that using DLookup() function will be slower
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 07-20-2015, 02:28 PM
  2. Auto-fill one field from another table
    By tasoper in forum Access
    Replies: 3
    Last Post: 06-13-2014, 07:17 AM
  3. Replies: 3
    Last Post: 03-21-2012, 01:43 PM
  4. Replies: 10
    Last Post: 11-21-2011, 02:56 AM
  5. Replies: 5
    Last Post: 01-20-2011, 11:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums