Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Query Help

Query Help

Scheduled Pinned Locked Moved Database
databasehelpquestion
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    solutionsville
    wrote on last edited by
    #1

    I have a Access Form, with a series of three combo boxes. Box 1 - City Box 2 - State Box 3 - ZIP When I input the zip code, I want to populate the other two boxes based on the result of the ZIP code. I have a ZIP codee table, which has ZIP, CITY, and a second table that has State. How should I write the query in order to accomplish this? Thanks,

    P S 2 Replies Last reply
    0
    • S solutionsville

      I have a Access Form, with a series of three combo boxes. Box 1 - City Box 2 - State Box 3 - ZIP When I input the zip code, I want to populate the other two boxes based on the result of the ZIP code. I have a ZIP codee table, which has ZIP, CITY, and a second table that has State. How should I write the query in order to accomplish this? Thanks,

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      You can obtain the City by doing a simple SELECT on your ZIP Code table, filtering on the ZIP. You haven't explained how your tables are related. I assume you have a City table with a foreign key to the State table. If so, write a query which joins the ZIP Code, City and State tables and fetches the corresponding State description.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      S 1 Reply Last reply
      0
      • P pmarfleet

        You can obtain the City by doing a simple SELECT on your ZIP Code table, filtering on the ZIP. You haven't explained how your tables are related. I assume you have a City table with a foreign key to the State table. If so, write a query which joins the ZIP Code, City and State tables and fetches the corresponding State description.

        Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

        S Offline
        S Offline
        solutionsville
        wrote on last edited by
        #3

        Hello Paul, and thank you for your response. I need to get better explaining my brainstorming! Ok, the Zipcode table has Zipcode, City, State Code fields. The State Table has State Code, State Abrieviation, and State Name. The two tables are related by the State Code field. I would think that if I enter the zip, then perform an after update event that queries the Zipcode table and populates the State field of the form. So, with the above in mind, would you think that this query would work? SELECT [ZIP Codes].[City], [States].[State Abbreviation] FROM [ZIP Codes], States WHERE [Zip Codes].[ZIP Code] = '44107' and [States].[State Code] = (SELECT [ZIP Codes].[State Code] FROM [ZIP Codes] WHERE [ZIP Codes].[ZIP Code] = '44107') ORDER BY [ZIP Codes].[ZIP Code]; Thanks,

        P 1 Reply Last reply
        0
        • S solutionsville

          Hello Paul, and thank you for your response. I need to get better explaining my brainstorming! Ok, the Zipcode table has Zipcode, City, State Code fields. The State Table has State Code, State Abrieviation, and State Name. The two tables are related by the State Code field. I would think that if I enter the zip, then perform an after update event that queries the Zipcode table and populates the State field of the form. So, with the above in mind, would you think that this query would work? SELECT [ZIP Codes].[City], [States].[State Abbreviation] FROM [ZIP Codes], States WHERE [Zip Codes].[ZIP Code] = '44107' and [States].[State Code] = (SELECT [ZIP Codes].[State Code] FROM [ZIP Codes] WHERE [ZIP Codes].[ZIP Code] = '44107') ORDER BY [ZIP Codes].[ZIP Code]; Thanks,

          P Offline
          P Offline
          pmarfleet
          wrote on last edited by
          #4

          solutionsville wrote:

          SELECT [ZIP Codes].[City], [States].[State Abbreviation] FROM [ZIP Codes], States WHERE [Zip Codes].[ZIP Code] = '44107' and [States].[State Code] = (SELECT [ZIP Codes].[State Code] FROM [ZIP Codes] WHERE [ZIP Codes].[ZIP Code] = '44107') ORDER BY [ZIP Codes].[ZIP Code];

          Your query is overly complicated and can be simplified to:

          SELECT [ZIP Codes].[City], [States].[State Abbreviation]
          FROM [ZIP Codes]
          INNER JOIN [States]
          ON [ZIP Codes].[State Code] = [States].[State Code]
          WHERE [ZIP Codes].[ZIP Code] = '44107'

          Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

          S 1 Reply Last reply
          0
          • P pmarfleet

            solutionsville wrote:

            SELECT [ZIP Codes].[City], [States].[State Abbreviation] FROM [ZIP Codes], States WHERE [Zip Codes].[ZIP Code] = '44107' and [States].[State Code] = (SELECT [ZIP Codes].[State Code] FROM [ZIP Codes] WHERE [ZIP Codes].[ZIP Code] = '44107') ORDER BY [ZIP Codes].[ZIP Code];

            Your query is overly complicated and can be simplified to:

            SELECT [ZIP Codes].[City], [States].[State Abbreviation]
            FROM [ZIP Codes]
            INNER JOIN [States]
            ON [ZIP Codes].[State Code] = [States].[State Code]
            WHERE [ZIP Codes].[ZIP Code] = '44107'

            Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

            S Offline
            S Offline
            solutionsville
            wrote on last edited by
            #5

            Thanks Paul. I Appreciate it. Brian

            1 Reply Last reply
            0
            • S solutionsville

              I have a Access Form, with a series of three combo boxes. Box 1 - City Box 2 - State Box 3 - ZIP When I input the zip code, I want to populate the other two boxes based on the result of the ZIP code. I have a ZIP codee table, which has ZIP, CITY, and a second table that has State. How should I write the query in order to accomplish this? Thanks,

              S Offline
              S Offline
              Steven J Jowett
              wrote on last edited by
              #6

              Here's a tip for you. Use the Access Query design to do you table links etc, then look at query as SQL Statement and there's the required code.

              Steve Jowett ------------------------- It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups