Isaac
Lifelong Learner
- Local time
- Today, 12:51
- Joined
- Mar 14, 2017
- Messages
- 8,777
Below is my code. I am getting "object invalid or no longer set" on the line rsInner.MoveNext
Despite the fact that I have:
Is this normal/expected? Is there any way around it other than I know I can just use a Currentdb.Execute to make the update, but am curious if there is anything else about this situation I should know.
Despite the fact that I have:
- opened an outer recordset as Recordset
- set a fld2 variable as outer recordset's Attachment field
- set an inner Recordset2 as fld2.value
Is this normal/expected? Is there any way around it other than I know I can just use a Currentdb.Execute to make the update, but am curious if there is anything else about this situation I should know.
Code:
Sub UpdateTaxonomyFilenames()
'Purpose: loop through outer recordset. loop through each one's Attachments
'Figure out which one's [short] filename is not equal to any one of 3 existing outer recordset's columns, AND exists in a certain folder,
'and then make an update to the outer recordset
Dim rsOuter As DAO.Recordset, db As DAO.Database, rsInner As DAO.Recordset2, fld As DAO.Field2
Dim strFileName As String
Set db = CurrentDb
Set rsOuter = db.OpenRecordset("select * from [distribution portal]")
Do Until rsOuter.EOF = True
Set fld = rsOuter.Fields("Attachments")
Set rsInner = fld.Value
Do Until rsInner.EOF = True
strFileName = rsInner.Fields("Filename").Value
strFileName = Right(strFileName, Len(strFileName) - InStrRev(strFileName, "/"))
'if it's not ccepfilename, and not filename_useruploaded1, and not *useruploaded2, and exists in that folder...then it's our originally uploaded taxonomy file
If (strFileName <> rsOuter.Fields("CCEPFilename").Value) And _
(strFileName <> rsOuter.Fields("Filename_UserUploaded_1").Value) And _
(strFileName <> rsOuter.Fields("Filename_UserUploaded_2").Value) And _
(Dir("\\server.com\folder\folder\folder\folder\folder\folder\folder\" & strFileName) <> "") Then
'then it's the originally uploaded taxonomy file:
rsOuter.Edit
rsOuter.Fields("Filename_TaxonomyOriginal").Value = strFileName
rsOuter.Update
End If
rsInner.MoveNext
Loop
rsInner.Close
Set rsInner = Nothing
rsOuter.MoveNext
Loop
rsOuter.Close
Set rsOuter = Nothing
End Sub