Search code examples
vbams-accessattachmentms-access-2013attachment-field

Determine if Attachment field is empty


How can you determine if in Attachment field in Access does not contain an attachment using VBA? I tried

If IsNull(rstMassBalance.Fields("FileName"))

and

If rstMassBalance.Fields("FileName") = Null

but neither of these work. It either does nothing or gives me run-time error 3021 that says "No current record"


Solution

  • I don't use the Attachments field, but the attachments are retrieved into a Recordset2 from the Value property of the attachments-field.

    Dim rsChild As DAO.Recordset2
    
    Set rsChild = rstMassBalance.Fields("FileName").Value
    

    I'm not sure if this will return Nothing or an empty recordset if there are no attachments. So either:

    If rsChild Is Nothing Then
    'or 
    If rsChild.RecordCount  <= 0 Then   'probably this one
    

    There is a lot of information to be garnered from this Access Blog.

    Work with Attachments in DAO suggests that you could check:

    If rsChild.EOF Then