Results 1 to 5 of 5
  1. #1
    whitelexi is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    20

    Unhappy List style combo box issue

    Hello everyone. I'm new to Access and need some help with a simple task which is giving me serious trouble. I have built a table called customer details and it contains a field called city, and another field for state. I want a user to be able to select a state from the stat combo box that i've created and have all the cities in the selected state appear in the city combo box.
    At the moment i created 2 tables (one for city and one for state) and i have every city and state packed into those tables, so when i click the city combo box, all the cities in the country are listed, but i want only the cities in the selected state to appear instead.
    Please can anyone help me with a workable solution?



    Many thanks in advance.

  2. #2
    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,848
    Do not use Lookups in Tables.
    see http://access.mvps.org/access/lookupfields.htm

    Use lookups in forms see comboboxes

    For combo boxes where select State, then only Cities for that State appear in the City combo ==> Cascading combos
    watch these free video tutorials
    http://www.datapigtechnologies.com/f...combobox1.html
    http://www.datapigtechnologies.com/f...combobox2.html

    Good luck

  3. #3
    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
    To begin with, you need a single Table for this, not separate city and state Tables. Each Record in this Table needs to have both state and city Fields. After you have that straight you can use this step-by-step:

    1. Place a Combobox on your Form
    2. When the Combobox Wizard comes up hit Cancel
    3. With the Combobox selected, go to Properties - Other
    4. In the Name Property enter cboStates
    5. Click on the Data Tab

    In the Row Source Property enter

    Code:
    SELECT DISTINCT tblStateCity.StateFieldName FROM tblStateCity ORDER BY [StateFieldName];

    Now go into the AfterUpdate event for your cboStates Combobox and use this code:

    Code:
    Private Sub cboStates_AfterUpdate()
    cboCities.RowSource = _
    "Select Distinct tblStateCity.CityFieldName " & _
        "FROM tblStateCity " & _
        "WHERE tblStateCity.StateFieldName = '" & cboStates.Value & "'" & _
        "ORDER BY tblStateCity.CityFieldName;"
    
    cboCities = ""
    
    End Sub


    Now repeat Steps 1-4, above, but in Step 4, instead of entering cboStates, enter the name cboCities.

    Replace tblStateCity with the actual name of your Table that contains both the Cities and States, and CityFieldName and StateFieldName with the actual names for these Fields from your Table.

    Linq ;0)>

  4. #4
    whitelexi is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    20
    Thanks everyone, with your help and suggestions, i've been able to resolve the issue... It works perfectly well now. Thanks again.

  5. #5
    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 we could help!

    Good luck with your project!

    Linq ;0)>

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

Similar Threads

  1. Phone List issue
    By Alfi54 in forum Forms
    Replies: 8
    Last Post: 04-17-2012, 09:47 AM
  2. Combo box dropdown style
    By desk4tbc in forum Programming
    Replies: 4
    Last Post: 10-05-2011, 05:55 PM
  3. List box drop Issue
    By JonM in forum Access
    Replies: 1
    Last Post: 09-30-2011, 12:56 PM
  4. list box goto record issue
    By Madmax in forum Access
    Replies: 2
    Last Post: 07-07-2011, 06:17 AM
  5. List Box Issue
    By Igawa29 in forum Programming
    Replies: 4
    Last Post: 02-22-2011, 01:19 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