After some trial and error, I got the code to work using this syntax:
When I tried to use the actual field name for Fields(1) the code ran without posting an error message, but the values did not get updated in the table. These are what I tried:
rsold!ncessch
rsold.Fields("ncessch")
Below is the code in case need to see in context. The reason I am doing it this way is that the linked table "ccd" is joined to a linked csv text file. When I tried to do a regular update query, received a message "Updating data in a linked table is not supported by this ISAM". To get around this (instead of creating multiple temp tables), I wrote the following which gets the data from the two tables and then updates the values from null to the actual value.
Code:
rs.FindFirst "ncesid = '" & rsold.Fields(1) & "'"
When I tried to use the actual field name for Fields(1) the code ran without posting an error message, but the values did not get updated in the table. These are what I tried:
rsold!ncessch
rsold.Fields("ncessch")
Below is the code in case need to see in context. The reason I am doing it this way is that the linked table "ccd" is joined to a linked csv text file. When I tried to do a regular update query, received a message "Updating data in a linked table is not supported by this ISAM". To get around this (instead of creating multiple temp tables), I wrote the following which gets the data from the two tables and then updates the values from null to the actual value.
Code:
Sub updateLocale_Click()
'Update locale where is null in CCD and found in text file
'20140529 ss
Dim rsold As DAO.Recordset
Dim rs As DAO.Recordset
Dim stsql As String
Dim intErr As Integer
Dim intRecsadded As Integer
Dim intListCount As Integer
On Error Resume Next
intRecsadded = 0
Set rsold = CurrentDb.OpenRecordset("SELECT tbl_CCD.unique_schid, tbl_CCD.ncesid, tbl_CCD.state, " & _
"tbl_CCD.locale, Ccd_11_appended_simplified.ulocal11 " & _
"FROM tbl_CCD " & _
"INNER JOIN Ccd_11_appended_simplified " & _
"ON tbl_CCD.ncesid = Ccd_11_appended_simplified.ncessch " & _
"WHERE tbl_CCD.locale Is Null")
Set rs = CurrentDb.OpenRecordset("Select * from tbl_CCD WHERE locale is null", dbOpenDynaset)
rsold.MoveLast
rsold.MoveFirst
rs.MoveLast
rs.MoveFirst
'Debug.Print rs.RecordCount & " " & rsold.RecordCount
With rs
'Find the corresponding record in the rs table based on the id in rsold and then
'update the value
Do While Not rsold.EOF
rs.FindFirst "ncesid = '" & rsold.Fields(1) & "'"
If Not rs.NoMatch Then
.Edit
rs!locale = rsold!ulocal11
intRecsadded = intRecsadded + 1 'keep a count of records added
.Update
End If
rsold.MoveNext
StatusBar "Processing row " & intRecsadded
Loop
intListCount = rsold.RecordCount
rs.Close
rsold.Close
End With
MsgBox intRecsadded & " records out of " & intListCount & " added from the list of ids. " & _
"If the count differs from the total, then those records were not " & _
"added because..." _
, vbOKOnly, "Update List..."
StatusBar ""
End Sub