How can I automatically fill a form field

  • Thread starter Thread starter Guest
  • Start date Start date
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!!!
 
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)
 
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!!!
 
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!!!
 
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.
 
Back
Top