automatic population of fields

L

Lauren B.

I currently have a populated table with the following fields:
1. Zip Code
2. County
3. Region

I want to set up my form so that when a user enters a zip code, the county
and region fields automatically populate with the correct information based
on the table.

What is the best way for me to accomplish this task?

Thank you in advance for any assistance.

LB
 
G

Guest

My approach would be something like this:

private sub TextZipCode_AfterUpdate()
dim rst as recordset
set rst = currentdb.openrecordset("MyZipCodeTable", dbOpenSnapShot)
rst.FindFirst "ZipCode = """ & TextZipCode & """"

if rst.noMatch then
msgbox "Unknown Zip Code", vbOkOnly + vbExclamation
else
textCounty = rst!County
textRegion = rst!Region
end if

rst.close
end sub

You still will need to change for the names of your table, fields and
textboxes, but It may work for you

Mauricio Silva
 
L

Lauren B.

Thank you for your assistance.

For some reason, I'm not able to get this to work. I had thought that
another approach would be to create a query as the row source for the Zip
Code field. The code would then read:

P_COUNTY = Me.ZIPCODE.Column(1)
P_REGION = Me.ZIPCODE.Column(2)

This does not work either. Do you have any thoughts about using a query?

Thanks.
 
G

Guest

Now I need more detail. How it doesn't work? Is there a error message or it
just doesn't appear?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top