MailEnvelope(MsoEnvelope)

J

Joop

Hi all

In an application I develope I want to send a word document via Outlook. So
I want to use MsoEnvelope to do that. I use the folowing code to accomplishe
that:

Private Sub CmdVerzEMail_Click()
Dim cn As ADODB.Connection
Dim rcdCor As New ADODB.Recordset
Dim SQLString As String
Dim DocPadString As String
Dim WApp As Object, OApp As Object
Set OApp = StartOutlook
Set cn = CurrentProject.Connection
SQLString = "SELECT * FROM TblCorres WHERE FldCorresID = " &
Me!TxtCorresID & ";"
rcdCor.Open SQLString, cn, adOpenKeyset, adLockOptimistic
DocPadString = rcdCor!FldCorresDir & rcdCor!FldCorresNaam & ".DOC"
Set WApp = StartWord
WApp.Documents.Open filename:=DocPadString
With WApp.ActiveDocument.MailEnvelope.Item
.To = "(e-mail address removed)"
.Subject = rcdCor!FldCorresOnderw
.send
End With
OApp.Application.Quit
WApp.Application.Quit wdDoNotSaveChanges
End Sub

StartOutlook and StartWord are functions that check if the application
already runs and if not it starts the application.

My question: Often when I run the code the Word document is not ready so the
"WApp.ActiveDocument.MailEnvelope.Item" generates an error (Object variable
or with block var not set). I think it is an timing problem. When I run the
code in debug mode it executes ok. How can I check if the objectproperties I
want to change are available??

thxx
Joop Aarts
 
T

TC

Maybe try this:

(untested)

dim x as single
x = timer()
on error resume next
do
doevents
-- bad code here --
loop until err.number = 0 or timer() > x + 5
if err.number = 0 then
msgbox "it worked"
else
msgbox "hadn't worked after 5 seconds!"
endif
on error goto 0

HTH,
TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top