Private Sub txtZipCode_AfterUpdate()
If IsNull(Me.[Zip Code]) Then Exit Sub
Dim db As DAO.Database
Dim RS As DAO.Recordset
Set db = CurrentDb()
Set RS = db.OpenRecordset("SELECT ZipCode, CityName, CountyName FROM tblCounty_CityData WHERE ZipCode =" & Me.txtZipCode & ";")
'If not found, pop up entry form
If RS.BOF And RS.EOF Then
DoCmd.OpenForm "frmAddZip", acNormal, , , acFormAdd, acDialog, Me.txtZipCode
Me.County.SetFocus
Me.txtZipCode.SetFocus
Else
RS.MoveFirst
RS.MoveLast
If RS.RecordCount > 1 Then
DoCmd.OpenForm "frmChooseCity", , , , , acDialog
Else
'If only one matching zip is found, fill City
Me.txtCITY = RS![CityName]
Me.County = RS![CountyName]
End If
End If
RS.Close
Set RS = Nothing
db.Close
Set db = Nothing
End Sub