I have a form, in which, when the user enters the zipcode, it should obtain the relevant city, state and county from the table.
After entering the zipcode, it gives out an error 3061 and highlights as below:
Set rstAny = dbAny.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
The fullcode is as below.
Private Sub txtZipCode_AfterUpdate()
Dim strSQL As String
Dim dbAny As DAO.Database
Dim rstAny As DAO.Recordset
strSQL = "SELECT Z.City, Z.StateCode, C.CountyCode, C.PrimaryPOPArea " & _
"FROM ZIPCodes As Z INNER JOIN ZipToCountyLink As C " & _
"ON Z.ZIPCode = C.ZIPCODE " & _
"WHERE Z.ZIPCode=" & Chr(34) & Me.txtZipCode & Chr(34) & _
" ORDER BY C.PrimaryPOPArea Asc"
Set dbAny = CurrentDb()
Set rstAny = dbAny.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
If rstAny.RecordCount > 0 Then
rstAny.MoveLast
rstAny.MoveFirst
Me.txtCity = rstAny!City
Me.txtState = rstAny!StateCode
End If
End Sub
Kindly help me in solving this problem.
After entering the zipcode, it gives out an error 3061 and highlights as below:
Set rstAny = dbAny.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
The fullcode is as below.
Private Sub txtZipCode_AfterUpdate()
Dim strSQL As String
Dim dbAny As DAO.Database
Dim rstAny As DAO.Recordset
strSQL = "SELECT Z.City, Z.StateCode, C.CountyCode, C.PrimaryPOPArea " & _
"FROM ZIPCodes As Z INNER JOIN ZipToCountyLink As C " & _
"ON Z.ZIPCode = C.ZIPCODE " & _
"WHERE Z.ZIPCode=" & Chr(34) & Me.txtZipCode & Chr(34) & _
" ORDER BY C.PrimaryPOPArea Asc"
Set dbAny = CurrentDb()
Set rstAny = dbAny.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
If rstAny.RecordCount > 0 Then
rstAny.MoveLast
rstAny.MoveFirst
Me.txtCity = rstAny!City
Me.txtState = rstAny!StateCode
End If
End Sub
Kindly help me in solving this problem.