Runtime 2351 on .Attachments.Add

  • Thread starter Thread starter Tony Vrolyk
  • Start date Start date
T

Tony Vrolyk

I am wondering what I am doing wrong here. The following code is giving me
an error. I can post more of it if need be.

The message is created, the recipients are set, the subject and body is set
ok, then it appear to stop. When I go back to the Access window it shows me
the runtime 2351 error "Operation is not supported for this type of object".
When I click Debug it has stopped at the .Attachments line

Maybe I am overlooking something simple but then again I was up for 4 hours
in the middle of the night last night with my son - so I am not at my best.
Any help would be appreciated.
Tony Vrolyk


'---code start---
With objMessage
.BCC = strBCCReceipient
.Subject = "blah blah blah"
.Body = "more blah blah blah"
.Importance = olImportanceHigh

Set rst = CurrentDb().OpenRecordset("SELECT FilePath, DocumentType FROM
qryRenewalWork_Documents_Include WHERE (RenewalWorkID)=" & Me.RenewalWorkID)

Do Until rst.EOF
.Attachments.Add rst!FilePath, olByValue, rst!DocumentType
Loop
rst.Close
Set rst = Nothing

.Display
End With
'---code end---
 
is "objMessage" a variable declared somewhere in your database? what is the
object type assigned to it?

Dim objMessage As ??

have you read up on the properties and methods available to the object type,
to verify that .Attachment is indeed available to this object type?

hth
 
I assume objMessage is an Outlook MailItem???

I can't claim that I know Outlook VBA but I think you need to use
olEmbeddedItem rather olByValue.

Try olEmbeddedItem and see if it works for you.

HTH
Van T. Dinh
MVP (Access)
 
I GOT IT!

Apparently the Add method doesn't like referring to a recordset field so I
changed it to a string variable. Also I noticed I had forgotten to move to
the next record so I added an rst.MoveNext. Below is what I ended up wtih.

Thanks for your help anyway
Tony


Dim objOutlook As Object
Dim objMessage As Object

Set objOutlook = CreateObject("Outlook.Application")
Set objMessage = objOutlook.CreateItem(olMailItem)

strProducer = DLookup("[Producer]",
"qryPolicies_GroupInForce_ClientInfo", "[PolicyID] = " & Me.PolicyID)

With objMessage
.BCC = strBCCReceipient
.Subject = "blah blah blah"
.Body = "blah blah blah"
.Importance = olImportanceHigh 'High importance

Set rst = CurrentDb().OpenRecordset("SELECT FilePath, DocumentType FROM
qryRenewalWork_Documents_Include WHERE (RenewalWorkID)=" & Me.RenewalWorkID)

'Here is the addition
Dim strPath As String
strPath = rst!FilePath

Do Until rst.EOF
.Attachments.Add strPath, olByValue
rst.MoveNext
Loop
rst.Close
Set rst = Nothing

.Display

End With
 
And of course I realized that the strig variable need to be set with each
loop so I moved that withing the loop.


Tony Vrolyk said:
I GOT IT!

Apparently the Add method doesn't like referring to a recordset field so I
changed it to a string variable. Also I noticed I had forgotten to move to
the next record so I added an rst.MoveNext. Below is what I ended up wtih.

Thanks for your help anyway
Tony


Dim objOutlook As Object
Dim objMessage As Object

Set objOutlook = CreateObject("Outlook.Application")
Set objMessage = objOutlook.CreateItem(olMailItem)

strProducer = DLookup("[Producer]",
"qryPolicies_GroupInForce_ClientInfo", "[PolicyID] = " & Me.PolicyID)

With objMessage
.BCC = strBCCReceipient
.Subject = "blah blah blah"
.Body = "blah blah blah"
.Importance = olImportanceHigh 'High importance

Set rst = CurrentDb().OpenRecordset("SELECT FilePath, DocumentType FROM
qryRenewalWork_Documents_Include WHERE (RenewalWorkID)=" &
Me.RenewalWorkID)

'Here is the addition
Dim strPath As String
strPath = rst!FilePath

Do Until rst.EOF
.Attachments.Add strPath, olByValue
rst.MoveNext
Loop
rst.Close
Set rst = Nothing

.Display

End With


Van T. Dinh said:
I assume objMessage is an Outlook MailItem???

I can't claim that I know Outlook VBA but I think you need to use
olEmbeddedItem rather olByValue.

Try olEmbeddedItem and see if it works for you.

HTH
Van T. Dinh
MVP (Access)
 
Back
Top