Results 1 to 6 of 6
  1. #1
    Rabastan is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Posts
    3

    Auto populate

    I am trying to build an Employee Database for my company. I cant figure out whay this is not working. I want to Auto Populate the city and state based on the zip code entered. for txtEmployeeZip I have the following


    Code:
    Private Sub txtEmployeeZip_AfterUpdate()
        txtEmployeeCity = DLookup("[zipCity]", "tblZip", "[zipCode]= '" & Me!txtEmployeeZip & "'")
        txtEmployeeState = DLookup("[zipState]", "tblZip", "[zipCode]= '" & Me!txtEmployeeZip & "'")
    End Sub



    It however does NOTHING. I have double checked 10 times and all my field names are correct.


    Thanks, Rab

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Given that you've double-checked all names, two things come to mind:

    Does any code execute when the Form is opened by simply clicking on it, in the Nav Pane? In version 2007 and later, when no VBA code executes, the problem is usually that the folder holding the database hasn’t been designated as a "Trusted" location.

    To "Trust" your folder, click:
    • Office Button (top left)
    • Access Options (bottom of dialog)
    • Trust Center (left)
    • Trust Center Settings (button)
    • Trusted Locations (left)
    • Add new location (button)


    Also, your syntax is only correct if the zipCode Field is defined as a Text Datatype. Is it? If it's defined as a Number, the syntax would be

    Code:
    Private Sub txtEmployeeZip_AfterUpdate()
        txtEmployeeCity = DLookup("[zipCity]", "tblZip", "[zipCode]= " & Me.txtEmployeeZip)
        txtEmployeeState = DLookup("[zipState]", "tblZip", "[zipCode]= " & Me.txtEmployeeZip)
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Rabastan is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Posts
    3
    Thanx for your reply, i added the folder into the trusted list, datatype is "short text" I dont know how to check if its executing code though.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Do debug.Prints right before and right after the line with a DLookup

    or use breakpoint and check the value as you step though the code

    You say you are building an Employee database, can you show us your relationships window as a jpg.
    I'm asking this since you have 2 posts and are dealing with an afterUpdate event on a Form.
    Good luck.

  5. #5
    Rabastan is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Posts
    3
    Figured out my problem, My zip code table wasn't complete. and just by happenstance the ones I was trying were the ones that were missing.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad you got it figured out!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. How do I auto populate several fields at once
    By learmanj in forum Programming
    Replies: 4
    Last Post: 07-20-2013, 11:41 AM
  2. Auto populate tbl
    By fodzilla in forum Access
    Replies: 3
    Last Post: 06-15-2012, 05:03 PM
  3. Complicated auto populate
    By duncthepunk in forum Forms
    Replies: 7
    Last Post: 03-17-2011, 10:37 PM
  4. Auto Populate
    By co_sportsguy in forum Access
    Replies: 3
    Last Post: 09-01-2010, 01:22 PM
  5. Auto-Populate Combo box
    By vincenoir in forum Forms
    Replies: 3
    Last Post: 10-14-2009, 07:06 AM

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