Zip code automation

P

Photios_Kim

I have a form where I put in customer's information. I also have a
table of zip codes and their corresponding towns and states. What I
want to do is make the for to where when the user enters the zip code,
the townand state automatically appear in their respective boxes.
Listed below is the code I used. The problem is that two towns are
assigned with one zip code. Even though I select second listed town,
but alwasy Town field is filled with town listed first. Anybody can
help me?
Thanks in advance.

Private Sub ServiceZip_AfterUpdate()

Dim varState, varTown As Variant
varState = DLookup("State", "ZipCodes", "Zip ='" & Me.[ServiceZip]
& "'")
varTown = DLookup("Town", "ZipCodes", "Zip = '" & Me.[ServiceZip] &
"'")
If (Not IsNull(varState)) Then Me![ServiceState] = varState
If (Not IsNull(varTown)) Then Me![ServiceTown] = varTown

End Sub
 
M

Mark

You could try using an unbound combo box (not tied to any field in the
form's record source). Make the row source of the combo box a query that
shows the zipcode, town and state. Set the column widths to show the zip
and the town so the user can choose the city they want if more than one city
has the same zip code. In the AfterUpdate event of the combo box, you can
set your text boxes to the values of the combo box columns something like
this:
Me.txtTown = Me.cboZipcodes.Column(1)
Me.txtState = Me.cboZipcodes.Column(2)
Me.cboZipcodes = ""
Mind you, this is just sample code off the top of my head; you'll have to
use the proper names based on your form design.
 

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

Top