Hi, John
Thank you so much for you quick response to my inquiry! I am sure it took
you some time to do all of that.
Well, it did back in 2002 when I first did it.... just copy & paste from an
open database today.
I like your idea of having the City Drop-down box set the zipcode. That's
exactly what I am wanting to do.
You can actually have it go both ways - fill in the city from the zipcode as
well.
However, you are talking to a real novice here. I know how to create a basic
Table, Database, and Form. That's it!
Can you walk me through it step by step even more than you have?
1. Where do I start? With "Dim rs As DAO.Recordset"?
2. Where do I go to enter this information?
3. Do I type it in exactly as you have it, line for line?
4. What am I actually doing?
You're creating a Subroutine which will be called every time a selection is
made in the City combo box. The subroutine will look up the zipcode (or codes)
for that city and take appropriate action.
Open the Form that you'll be using in design. I assume that you have Combo
Boxes on the form for the zipcode and city - if not create them. For
simplicity of editing the code, you may want to change the name of the zipcode
combo box to cboZip and that of the city to cboCity; otherwise you'll need to
edit the code to replace cboZip and cboCity with the actual name of your combo
boxes. My code also assumes that you have a combo box named cboState with the
two-letter state code.
Select the zip code combo box (cboZip let's say) and view its Properties. On
the Events tab, find the AfterUpdate event. Click the ... icon next to it, and
select "Code Builder". Access will give you two lines - Private Sub
cboZip_AfterUpdate() and End Sub. Copy and paste (you don't need to retype)
the code from my message onto these, replacing them.
You'll need to fix a few lines that word-wrapped in the message here (I don't
know what newsreader you're using so I'm not sure whether that will be an
issue).
My code uses a table named CONtblZIp with fields Zip and City. You presumably
have a similar table in your database - edit the code to replace CONtblZip
with the name of this table, and the fieldnames Zip and City with the actual
fieldnames from your table.
When you're done editing these changes, select Debug... Compile <my database>
from the menu. Grumble at me about the (likely) error messages; correct them
all, recompiling each time.
Click the diskette icon on the toolbar to save the project.
Open your form and try out the combo - and let me know how it works!
John W. Vinson [MVP]