Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto fill code not working

Status
Not open for further replies.

derrickchanson

Technical User
Jan 11, 2002
7
US
I am trying to get an "address", "state", and "city" field to automatically fill in on a form based on the selection from a listbox called "site".

The "Site" field list comes from a separate table called "tbldistricts", which contain the matching address, city, and state for the site.

When I enter a site in the field the address, city, and state fields fill in automatically, but with the same information everytime, never changing.

Here is the code I entered for the "site" field:

Private Sub Site_Exit(Cancel As Integer)
Dim varAddress1, varCity, varState As Variant
Address1 = DLookup("Address1", "tblDistricts", "Site =[Site]")
City = DLookup("City", "tblDistricts", "Site = [Site]")
State = DLookup("State", "tblDistricts", "Site = [Site]")
If (Not IsNull(varAddress1)) Then Me![Address1] = Address1
If (Not IsNull(varCity)) Then Me![City] = City
If (Not IsNull(varState)) Then Me![State] = State
End Sub

Why are the address, city, and state not filling in properly?

Thanks
Derrick
 
Here is another code that does work, but only when the "Site" field is not a Combobox. In this situation the site field is called "Intitute" on the form and "site" in the table "tbldistricts"

Private Sub Institute_Exit(Cancel As Integer)
Dim varAddress1, varCity, varZipCode, varState As Variant
varAddress1 = DLookup("Address1", "tblDistricts", "Site = [Institute]")
varCity = DLookup("City", "tblDistricts", "Site = [Institute]")
varState = DLookup("State", "tblDistricts", "Site = [Institute]")
If (Not IsNull(varAddress1)) Then Me![Address1] = varAddress1
If (Not IsNull(varCity)) Then Me![City] = varCity
If (Not IsNull(varState)) Then Me![State] = varState

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top