Since you are writing code, you should learn about passing arguments (variables) to procedures.
http://msdn.microsoft.com/en-us/libr...=vs.60%29.aspx
http://www.cpearson.com/excel/byrefbyval.aspx
Here is the subroutine I came up with:
Code:
Public Sub GetCityState(pstrForm As Form, pZip As Long)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim frm As Form
Set db = CurrentDb
Set frm = pstrForm
Set rs = db.OpenRecordset("SELECT City, StateAbreviation from ZIPCodeQ WHERE ZIPCodeID=" & pZip)
If (rs.BOF And rs.EOF) Then
MsgBox "Zip code - " & pZip & " not found"
Else
frm!StateAbreviation = rs!StateAbreviation
frm!City = rs!City
End If
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Set frm = Nothing
End Sub
You call it like this:
Code:
Private Sub Combo3_AfterUpdate()
Call GetCityState(Me, Combo3)
End Sub