Access hangs inconsistently depending on the machine and debug mode | Member | | Join Date: Nov 2006
Posts: 118
| |
I have the following code in a VBA Access module. -
Declare Function MAPISendMail Lib "Mapi32.dll" _
-
Alias "BMAPISendMail" (ByVal Session&, _
-
ByVal UIParam&, _
-
Message As MAPIMessage, _
-
Recipient() As MapiRecip, _
-
File() As MapiFile, _
-
ByVal Flags&, _
-
ByVal Reserved&) As Long
-
which is called by: -
SendMail = MAPISendMail(0&, 0&, MAPI_Message, MAPI_Recip(), MAPI_File(), MAPI_LOGON_UI, 0)
-
The code sends an email with the required recipients, subject, body and attachements. On one machine, the code works without any problems. On another machine, when run from a form that triggers the code, it hangs at the SendMail line.
However, if I put a break point at the SendMail line and step through the code, I experience no problems.
This seems to be wonderfully inconsistent to me. Has anyone experienced this before or can anyone offer a pointer to resolve this issue?
Many thanks.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Access hangs inconsistently depending on the machine and debug mode
I don't think a new thread was necesary however we are here.
Did you try the two methods I mentioned in the other thread?
I also thought you stated that the sendobject method was working for you?
If I were using Mapi I would add a reference in my VBA window to Outlook once that is done you can use something like the following and this should help you track down your problem. I did a bit of searching and the method you are using does have some issues, I didn't see any definitive work arounds just people poking about. -
Dim appOutLook As Outlook.Application
-
Dim MailOutLook As Outlook.MailItem
-
Set appOutLook = CreateObject("Outlook.Application")
-
Set MailOutLook = appOutLook.CreateItem(olMailItem)
-
You can also use CDONTS to send mail as an alternative.
| | Member | | Join Date: Nov 2006
Posts: 118
| | | re: Access hangs inconsistently depending on the machine and debug mode
SendObject did work for me, but I was only able to send snapshot views using this method. I wanted to send files that could be read easily by any user and resorted to pdf reports as that was the best solution I could find. This then moved the problem to creating pdf's and then attaching them to an email, and sending that email. Hence the new post.
I am able to use the pdf method on a couple of machines, but the trouble I describe above occurs on a third machine. It is possible that this machine has some kind of software installation issue, or perhaps the method I am using is prone to instabilities.
This is what I am not sure about.
I have tried the DoEvents and DBEngine.Idle but it did not help, unfortunately. I will look into your suggestions...
|  | Expert | | Join Date: Apr 2006 Location: Philadelphia
Posts: 5,214
| | | re: Access hangs inconsistently depending on the machine and debug mode Quote:
Originally Posted by billelev I have the following code in a VBA Access module. -
Declare Function MAPISendMail Lib "Mapi32.dll" _
-
Alias "BMAPISendMail" (ByVal Session&, _
-
ByVal UIParam&, _
-
Message As MAPIMessage, _
-
Recipient() As MapiRecip, _
-
File() As MapiFile, _
-
ByVal Flags&, _
-
ByVal Reserved&) As Long
-
which is called by: -
SendMail = MAPISendMail(0&, 0&, MAPI_Message, MAPI_Recip(), MAPI_File(), MAPI_LOGON_UI, 0)
-
The code sends an email with the required recipients, subject, body and attachements. On one machine, the code works without any problems. On another machine, when run from a form that triggers the code, it hangs at the SendMail line.
However, if I put a break point at the SendMail line and step through the code, I experience no problems.
This seems to be wonderfully inconsistent to me. Has anyone experienced this before or can anyone offer a pointer to resolve this issue?
Many thanks. Does the 'hanging machine' have a MAPI complient E-Mail application installed - if not, I imagine the code will fail.
| | Member | | Join Date: Nov 2006
Posts: 118
| | | re: Access hangs inconsistently depending on the machine and debug mode Quote:
Originally Posted by ADezii Does the 'hanging machine' have a MAPI complient E-Mail application installed - if not, I imagine the code will fail. It had Outlook installed.
I have just added the Microsoft Outlook reference on the VBA screen, and the hanging machine now works without any problems.
The weird thing is that the other two machines executed the code without the Outlook reference. Bizarre. And the code on the (now previously) hanging machine would work if I stepped through the code using the debugger.
Thank you all for your help.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Access hangs inconsistently depending on the machine and debug mode
Glad you got it, just something to think of, I use CDO for most of my exports this allows me to export into an HTML file, then embed the html into the email body, this can also be done using MAPI but I seem to have less trouble with CDO .... However some companies and or people don't allow HTMl messages in the emails so it can lose some structuring when that happens. Fortunately at this company no one has complained so I think they all have HTML email bodies turned on.
My code for CDO is a bit extensive but here is a snippet of one where I used MAPI: -
Set ol = CreateObject("Outlook.Application")
-
Set ns = ol.getNamespace("MAPI")
-
ns.logon "", "", True, False
-
Set iMsg = ol.CreateItem(olMailItem)
-
Set ts = FSO.OpenTextFile(Application.CurrentProject.Path & "\InvLG.HTML", ForReading, True) '.CreateTextFile(vFile)
-
tsR = ts.ReadAll
-
-
With iMsg
-
.HTMLBody = tsR
-
-
Hope all goes well any more questions let us know.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,419 network members.
|