How can I automatically fill a form field

G

Guest

I have a form that I use to enter data into a table. One of the things I am
entering is an address. I am trying to find a way to type in the zip code
and have the city automaticcaly fill into the form, based off of a seperate
table I have with the cities and zip codes. I do not want the field to be
limited to the list.

I know little about Access and have completely confused myself. Please
Help!!!
 
W

Wayne Morgan

In the AfterUpdate event where you type in the zip code try something like:

Me.txtCity = DLookup("[CityName]", "[LookupTableName]", "[ZipCode]='" &
Me.txtZipCode & "'")

This assumes the zip code to be a text field. If it is a number field:

Me.txtCity = DLookup("[CityName]", "[LookupTableName]", "[ZipCode]=" &
Me.txtZipCode)
 
G

Guest

That does not seem to be working. I get an error message that says Microsoft
Access can't fing the Macro Me. Like I said, I know little about Access, So
I do not know how to write Macros, or what this means. I there anything else
that might help me figure this out?

Wayne Morgan said:
In the AfterUpdate event where you type in the zip code try something like:

Me.txtCity = DLookup("[CityName]", "[LookupTableName]", "[ZipCode]='" &
Me.txtZipCode & "'")

This assumes the zip code to be a text field. If it is a number field:

Me.txtCity = DLookup("[CityName]", "[LookupTableName]", "[ZipCode]=" &
Me.txtZipCode)

--
Wayne Morgan
MS Access MVP


Chandra said:
I have a form that I use to enter data into a table. One of the things I
am
entering is an address. I am trying to find a way to type in the zip code
and have the city automaticcaly fill into the form, based off of a
seperate
table I have with the cities and zip codes. I do not want the field to be
limited to the list.

I know little about Access and have completely confused myself. Please
Help!!!
 
I

Iggv

replace TxtCity with the name of the box where you write the zipcode (i.e.
if that bos is Zipcod = Me.Zipcod)
Chandra said:
That does not seem to be working. I get an error message that says Microsoft
Access can't fing the Macro Me. Like I said, I know little about Access, So
I do not know how to write Macros, or what this means. I there anything else
that might help me figure this out?

Wayne Morgan said:
In the AfterUpdate event where you type in the zip code try something like:

Me.txtCity = DLookup("[CityName]", "[LookupTableName]", "[ZipCode]='" &
Me.txtZipCode & "'")

This assumes the zip code to be a text field. If it is a number field:

Me.txtCity = DLookup("[CityName]", "[LookupTableName]", "[ZipCode]=" &
Me.txtZipCode)

--
Wayne Morgan
MS Access MVP


Chandra said:
I have a form that I use to enter data into a table. One of the things I
am
entering is an address. I am trying to find a way to type in the zip code
and have the city automaticcaly fill into the form, based off of a
seperate
table I have with the cities and zip codes. I do not want the field to be
limited to the list.

I know little about Access and have completely confused myself. Please
Help!!!
 
W

Wayne Morgan

It isn't a "macro", it is VBA code. In form design mode, go to the
Properties for the for the zip code textbox. Go to the Events tab and in the
On After Update box choose Event Procedure. Click the ... button and it will
take you to that procedure in the VBA editor. Use the line of code I gave,
substituting the actual names of your textboxes for the ones I used.
 

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

Similar Threads

Auto Fill 0
HOW DO I GET A FIELD TO AUTOMATICALLY FILL IN? 2
Access forms fill in 1
How to accomplish this ? 3
Error on closing a form 4
#NAME? Error on Form 2
Give error message 0
dependent combo boxes 1

Top