Arghh !!! I'm having trouble debugging this SQL statement.
Private Sub ReplaceAirportNames_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT CountryID, CountryName FROM tblCountry"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
Do While rs.EOF = False
strSQL = "UPDATE tblAirports" & _
"SET tblAirports.Country = Replace([Country],'" & _
rs!CountryNAME & "','" & _
rs!CountryID & "') " & _
"WHERE tblAirports.Country = rs!CountryNAME"
db.Execute strSQL, dbFailOnError
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
I get Syntax error 3144.
I THINK the problem is in the "WHERE ... " part of the statement as I never seem to get this right.
What it is supposed to do: tblCountry has CountryID and CountryName. tblAirports has text field, Country. Basically, I want to turn this into a field that references the tblCountry.CountryID field by replacing the text string in tblAirports.Country with
the numeric value of tblCountry.CountryID.
tblCountry has around 200 records but tblAirports has over 9000. I've downloaded both datasets from the internet and imported them into Access.
All help appreciated.