G
Guest
On a form I want to create an expression so that if field (City)="Cambridge"
then field Zip Code = "12345". I don't know how to create it properly?
Help!
then field Zip Code = "12345". I don't know how to create it properly?
Help!
Nick said:On a form I want to create an expression so that if field
(City)="Cambridge" then field Zip Code = "12345". I don't know how
to create it properly? Help!
ndalton said:I'll assume for description's sake that the city will be in a combo box
control and the zip code will be in a text box (either one could be either
control; it's coded basically the same way).
I assume you have a table that lists all the cities and their corresponding
zip codes. We'll call this tblCities. Your city combo box (or whatever it
happens to be) should have a row source something like:
SELECT [tblCities].[CityName] FROM [tblCities]
Since the zip code depends on the city, your zip code text box should have a
row source that takes the value in the city box into account, like so:
SELECT [tblCities].[ZipCode] FROM [tblCities] WHERE [tblCities].[CityName] =
Me.CityComboBox
This select statement chooses the zip code that goes with the city that is
listed in the city box (I called it CityComboBox).
The last thing you might need to do is make sure that the zip code box gets
updated with the right zip code if the city box changes value. We can use
the CityComboBox's "After Update" event to trigger our code, which is simply:
Me.ZipCodeTextBox.Requery
Hope that helps. Good luck.
-ndalton
Nick said:On a form I want to create an expression so that if field (City)="Cambridge"
then field Zip Code = "12345". I don't know how to create it properly?
Help!