I've been trying for days to write a procedure to attach a simple file to an existing table.
The code for creating the temp table is working and the data has been pulled in using a SQL command.
The third subroutine creates two recordset entities and I then want to loop through the parent recordset and attach the same file to each record in the temptable.
when I execute this code I get one attachment loaded into the first record, but then get a Run time error '3420' - invalid object or no longer set.
I reckon my issue lies with how I fit both recordsets together in the loop.
As you can probably tell, my VBA experience is somewhat lacking. I hope someone with much more experience can give me a much needed pointer.
The code for creating the temp table is working and the data has been pulled in using a SQL command.
The third subroutine creates two recordset entities and I then want to loop through the parent recordset and attach the same file to each record in the temptable.
Code:
Sub objAtt1() 'Attaches a generic file to the temporary table
Dim Db As DAO.Database
Dim recSet As DAO.Recordset2
Dim recSet2 As DAO.Recordset2
Dim objFld As DAO.Field2
Set Db = CurrentDb
Set recSet = Db.OpenRecordset("tbltemptbl") 'A - Set the parent recordset
Set objFld = recSet.Att1
Set recSet2 = objFld.Value 'B - Set the child recordset
recSet.Edit 'C
Do Until recSet.EOF
recSet2.AddNew
recSet2.Fields("FileData").LoadFromFile "C:\Temp\GenericAttachment_1.pdf" 'C
recSet2.Update
recSet.Update
recSet.MoveNext 'Need this to prevent endless loop
Loop
End Sub
when I execute this code I get one attachment loaded into the first record, but then get a Run time error '3420' - invalid object or no longer set.
I reckon my issue lies with how I fit both recordsets together in the loop.
As you can probably tell, my VBA experience is somewhat lacking. I hope someone with much more experience can give me a much needed pointer.