Input one field, populate another

  • Thread starter Thread starter FJB
  • Start date Start date
F

FJB

I use a form to input data into the table. There is a field on the form
which we would like to have filled automatically from another table
based on a value entered in another field. For example, if you put
30303 in a zip code field, the form would automatically put "Atlanta,
GA" in the designated field. I'm not sure what to call this
procedure, but how is it done?. Thanks for your help.

Frank
 
Put the following statement in the BeforeUpdate event of the form
control in which the user enters the zipcode:

(untested)

dim v as variant
v = dlookup ("[LLLL]", "[TTTT]", "[ZZZZ]=""" & me![BBBB] & """")
if isnull(v) then
beep
msgbox "Unknown postcode!"
cancel = true
else
me![CCCC] = v
endif

Replace:

TTTT with the name of the lookup table containing the zipcode/location
information;
LLLL with the name of the location field in that table;
ZZZZ with the name of the zipcode field in that table;
BBBB with the name of the form control where the user enters the
zipcode;
CCCC with the name of the form control where you want to display the
location.

My cod rejects unknown pstcodes. YMMV. You might wan to ask for the
user to enter the location so you can automatically add that recrd to
the zipcode table.

HTH,
TC (MVP Access)
htp://tc2.atspace.com
 
Setup a table for Zipcodes, City, State, county......
Use it to populate a combo Zip control with a query. You can use the
column values to set the city, state and whatever after the zip is selected.
 
Back
Top