0

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"

Erik A
  • 31,639
  • 12
  • 42
  • 67
user2521720
  • 59
  • 1
  • 3
  • 7

1 Answers1

0

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
Andy G
  • 19,232
  • 5
  • 47
  • 69
  • I tried that and rsChild does in fact equal nothing, which I can see while debugging, however, I can not do Set rsChild = rstMassBalance.Fields("FileName").Value because it says there is no current record – user2521720 Jul 18 '13 at 14:41
  • UPDATE: I got it to work. You don't actually need to use a child recordset of the attachment field, if you simply do 'If rstMassBalance.RecordCount <= 0' that works. Thanks for your help. – user2521720 Jul 18 '13 at 15:18