0

This is my first time actually posting in a forum so let me know if I am using any bad practice here.

I am using access to organize iMessage data to format into a human-readable book. The database contains timestamp and attachment filename fields. The actual attachment file names contain said timestamp and filename values with some filler between. My goal is to parse through several thousand texts and import all attachments where applicable. See example below.

Database Example: https://i.stack.imgur.com/6rcgi.png

File Example: https://i.stack.imgur.com/0xvjy.png

I have the module written out as seen below and am getting "Error: "Run-time error '424': Object required" referencing line 27. Very helpful, Microsoft.

Option Compare Database

Function ImportAttach()

Dim db As DAO.Database
Dim rs As DAO.Recordset2
Dim rsT As DAO.Recordset2
Dim rsA As DAO.Recordset2
Dim fldT As DAO.Field2
Dim fldA As DAO.Field2

Dim strTimeStamp As String
Dim strFileName As String
Dim strPath As String
Dim strFile As String
 
Set db = CurrentDb
Set rs = db.OpenRecordset("iMessageDB")
Set fldT = rs("TimeStamp")
Set fldA = rs("Attachment")

strFilePath = "C:\Users\XPS\Documents\Projects\iMessage Book\attachments\"

rs.MoveFirst

Do Until rs.EOF
    Set rsT = fldT.Value '<-- Error Here
    Set rsA = fldA.Value

    If IsNull(strFileName) Then
        rs.MoveNext
    Else
        strFile = Dir(strPath & strTimeStamp & "*" & strFileName)
        rs.Edit
        
        rsA.AddNew
        rsA("FileData").LoadFromFile strPathFileName
        rsA.Update
    End If
    
    strFile = Dir
    rsA.Close
    rs.Update
    rs.MoveNext
Loop

rs.Close
db.Close
    
Set fldT = Nothing
Set fldA = Nothing
Set rsT = Nothing
Set rsA = Nothing
Set rs = Nothing
Set db = Nothing

End Function

I have not found a good solution elsewhere, so I appreciate any help.

braX
  • 11,506
  • 5
  • 20
  • 33
  • 1
    `fldT.Value` doesn't correspond to an object-type value: looks like a date or a timestamp field (in any case most likely not a recordset object)? You can't use Set to assign a non-object value. – Tim Williams Jan 09 '22 at 02:21
  • 1
    Also you're testing for `IsNull(strFileName)` but your code never assigns a value to that variable. – Tim Williams Jan 09 '22 at 02:28
  • 1
    A variable explicitly declared as string or number types cannot hold a Null. Attempting to will cause run-time error. So the test for Null would be irrelevant, test for empty string. – June7 Jan 09 '22 at 03:27
  • Embedding objects in db can use up Access 2GB size limit. Recordset2 is used to open an Attachment field into a recordset. It would normally be set with Attachment field from parent Recordset object. – June7 Jan 09 '22 at 04:15
  • 1
    Does this answer your question? [How do I use Access VBA to update a multivalue field](https://stackoverflow.com/questions/49245029/how-do-i-use-access-vba-to-update-a-multivalue-field) – June7 Jan 09 '22 at 04:15
  • 1
    Or this https://stackoverflow.com/questions/18237180/add-view-attachments-using-ms-access-vba – June7 Jan 09 '22 at 04:17

0 Answers0