Connecting Tech Pros Worldwide Forums | Help | Site Map

Access hangs inconsistently depending on the machine and debug mode

Member
 
Join Date: Nov 2006
Posts: 118
#1: Mar 27 '07
I have the following code in a VBA Access module.

Expand|Select|Wrap|Line Numbers
  1. Declare Function MAPISendMail Lib "Mapi32.dll" _
  2.                               Alias "BMAPISendMail" (ByVal Session&, _
  3.                               ByVal UIParam&, _
  4.                               Message As MAPIMessage, _
  5.                               Recipient() As MapiRecip, _
  6.                               File() As MapiFile, _
  7.                               ByVal Flags&, _
  8.                               ByVal Reserved&) As Long
  9.  
which is called by:

Expand|Select|Wrap|Line Numbers
  1. SendMail = MAPISendMail(0&, 0&, MAPI_Message, MAPI_Recip(), MAPI_File(), MAPI_LOGON_UI, 0)
  2.  
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.

Denburt's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#2: Mar 29 '07

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.

Expand|Select|Wrap|Line Numbers
  1. Dim appOutLook As Outlook.Application
  2.         Dim MailOutLook As Outlook.MailItem
  3.         Set appOutLook = CreateObject("Outlook.Application")
  4.         Set MailOutLook = appOutLook.CreateItem(olMailItem)
  5.  
You can also use CDONTS to send mail as an alternative.
Member
 
Join Date: Nov 2006
Posts: 118
#3: Mar 29 '07

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...
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,214
#4: Mar 29 '07

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.

Expand|Select|Wrap|Line Numbers
  1. Declare Function MAPISendMail Lib "Mapi32.dll" _
  2.                               Alias "BMAPISendMail" (ByVal Session&, _
  3.                               ByVal UIParam&, _
  4.                               Message As MAPIMessage, _
  5.                               Recipient() As MapiRecip, _
  6.                               File() As MapiFile, _
  7.                               ByVal Flags&, _
  8.                               ByVal Reserved&) As Long
  9.  
which is called by:

Expand|Select|Wrap|Line Numbers
  1. SendMail = MAPISendMail(0&, 0&, MAPI_Message, MAPI_Recip(), MAPI_File(), MAPI_LOGON_UI, 0)
  2.  
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
#5: Mar 29 '07

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.
Denburt's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#6: Mar 30 '07

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:

Expand|Select|Wrap|Line Numbers
  1. Set ol = CreateObject("Outlook.Application")
  2. Set ns = ol.getNamespace("MAPI")
  3. ns.logon "", "", True, False
  4. Set iMsg = ol.CreateItem(olMailItem)
  5.  Set ts = FSO.OpenTextFile(Application.CurrentProject.Path & "\InvLG.HTML", ForReading, True) '.CreateTextFile(vFile)
  6.  tsR = ts.ReadAll
  7.  
  8. With iMsg
  9. .HTMLBody = tsR
  10.  
  11.  
Hope all goes well any more questions let us know.
Reply