gkimmer
04-18-2005, 09:59 PM
I have 3 text boxes...for city, state and zip respectively.
I have a list of 200 zip codes with the corresponding city and state in a spreadsheet (or it could be put into an Access database too).
Based on the zip code that the user puts in, I want to fill in the city and state. How can I do this? Thanks!
gkimmer
04-19-2005, 08:52 AM
I have 3 text boxes...for city, state and zip respectively.
I have a list of 200 zip codes with the corresponding city and state in a spreadsheet (or it could be put into an Access database too).
Based on the zip code that the user puts in, I want to fill in the city and state. How can I do this? Thanks!
Have I stumped everyone, or is this just a simple thing that I should know how to do? haha... :)
Any help on this would be very welcome...somewhat time critical. Thanks!
spikey_richie
04-19-2005, 08:57 AM
You'd need to use a DB and use an SQL search from a command button or user key press. This is purely an example:
Public Sub updateTree()
Dim indx As Integer
Dim rsAllNames As Recordset
Dim sqlNames As String
Dim currentAlpha As String
Dim sContactName As String
Timer1.Enabled = True
tvContact.Visible = False
tvContact.Nodes.Clear
sqlNames = "SELECT ContactID, LastName, FirstName, MiddleInitial "
sqlNames = sqlNames & "FROM Contact ORDER BY"
sqlNames = sqlNames & " LastName, FirstName, MiddleInitial "
Set rsAllNames = dbContact.OpenRecordset(sqlNames)
If (rsAllNames.RecordCount > 0) Then
rsAllNames.MoveFirst
End If
For indx = Asc("A") To Asc("Z")
currentAlpha = Chr(indx)
Set contactNode = tvContact.Nodes.Add(, , currentAlpha, currentAlpha)
If (Not rsAllNames.EOF) Then
Do While UCase$(Left(rsAllNames!Lastname, 1)) = currentAlpha
With rsAllNames
sContactName = !Lastname & ", "
sContactName = sContactName & !Firstname
If (Not IsNull(!MiddleInitial)) Then
sContactName = sContactName & " " & !MiddleInitial & "."
End If
End With
DoEvents
Set contactNode = tvContact.Nodes.Add(currentAlpha, tvwChild, "ID" & CStr(rsAllNames!ContactID), sContactName)
rsAllNames.MoveNext
If (rsAllNames.EOF) Then
Exit Do
End If
Loop
End If
Next
sbStatus.Panels.Item(1).Text = "There are " & rsAllNames.RecordCount & " contacts in the database."
rsAllNames.Close
Timer1.Enabled = False
tvContact.Visible = True
DoEvents
End Sub
Diurnal
04-19-2005, 09:00 AM
If it is in a database, you can querry it for the city and state based on the zipcode. If it is in a file, load the file into an array, loop through the array and find the correct zip code. That will point you to the state and city elements. You might want to read the File I/O Tutorial (http://www.xtremevbtalk.com/showthread.php?threadid=123814) for more information on moving file data into an array.