By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,748 Members | 1,264 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,748 IT Pros & Developers. It's quick & easy.

vbSendMail.dll and MyMail.ocx -- Clues wanted

prn
Expert 100+
P: 254
Hi folks,

I'm trying to add an email function to an existing Access application. I'm not irrevocably committed to any particular method, so I'm open to suggestions like "try <whatever>." However, in looking around, I found references to vbSendMail.dll as a useful way of doing this without going through Outlook. Looking some more, I found MyMail.ocx, which is intended to help interface Access to vbSendMail.dll. "Great!" I thought, so I downloaded them, installed them, and tried out the MailTester.mdb that came with MyMail. It worked fine for me.

Now comes the interesting part. I made up a new form for the app I am working on and ran some tests with it to make sure it picks out the correct data, etc. That went fine too. Next I added references to MyMail and it bombed. I got the dreaded Access error message box "The expression OnClick you entered as the event property setting produced the following error: User-defined type not defined."

I have removed essentially everything to isolate the problem and the minimal difference turns out to be in the line:
Expand|Select|Wrap|Line Numbers
  1. Private WithEvents poSendMail As MyMail.clsSendMail
With that line commented out, my form "works" perfectly (even though it does not yet actually send mail). But with that line uncommented, it crashes as soon as I click on btnSend, the only event procedure currently in the form's code. The current version of my subroutine has been stripped down for testing and does not actually use anything, but I still get the same message. And I get that message regardless of whether the event procedure for OnClick refers to poSendMail or not. (I had to check that too, in case there would turn out to be a problem declaring WithEvents but not using anything in the class.)

I first got the error for the OnCurrent event and I realized that the MailTester.mdb did not use OnCurrent, so I considered the possibility that maybe MyMail.ocx was not equipped to handle OnCurrent. As I understand it, the WithEvents statement passes events from the object to the class, and I'm not sure exactly how that works, so I eliminated OnCurrent from my code (at least for the moment). But I still got the same error. I eliminated everything from my form's code except the event procedure Private Sub btnSend_Click() that appears in the MailTester.mdb (I even made sure to give the button the same name). I still get the same error message box.

I know the WithEvents statement in my code is the same as in MailTester.mdb because I copied and pasted it. I know that the code of the OnClick event procedure is not the problem because all it does is pop up a message box for each recipient telling me that it would send mail to that person (if it knew how) and it does that just fine as long as the WithEvents statement is not active. Therefore, I think it's safe to conclude that the error occurs when the event procedure tries to pass the event to a corresponding event handler that is part of the clsSendMail class, but just doesn't know how to deal with events at all. I know that MyMail.ocx is registered because it works perfectly in MailTester.mdb, but it bombs in my app. I know the vbSendMail.dll is present and registered for the same reason. Nevertheless, I reregistered both of them, following which MailTester.mdb still works and the real app that I am working on still does not work and still fails in the same way described.

I have to be overlooking something, but I don't know what.

Any clues gratefully accepted.

Thanks,
Paul
May 30 '07 #1
Share this Question
Share on Google+
1 Reply

prn
Expert 100+
P: 254
prn
Hi folks,

Well, as often happens, once you compose and post a reasonably clear statement of the problem, the answer appears. And, as usual, it's "obvious" once you realize what you missed.

I'm posting this to document the solution for the next person who tries to use a search engine to answer a similar question

The MyMail site says:
To use the OCX in your own program, just add a reference to MyMail in the code.
and the demo MailTester.mdb distributed with the OCX includes this:
Expand|Select|Wrap|Line Numbers
  1. Private WithEvents poSendMail As MyMail.clsSendMail
  2. ' Reference to c:\windows\system\MyMail.OCX
which appears to be the requisite reference. (Of course, it should also be noted that, by default, the installer provided with MyMail actually installs the file as c:\Program Files\MyMail\MyMail.ocx and NOT in c:\windows\system, but that may just be a quibble since the location is just in a comment.)

However, it's not enough to "just add a reference to MyMail in the code." You also have to add a refernce (in the VB window) under Tools>References. You need to click Tools from the menu bar, select Refernces from the drop-down, browse to c:\Program Files\MyMail (or whereever else it might actually be), select "Files of type: ActiveX Controls (*.ocx)" and then select MyMail.ocx to "Open". Make sure the resulting reference to "MyMail: Control to send mail from Access" is checked and click "OK" to close the dialog.

Once you see it, it's obvious. Until you see it, something's missing.

I hope this helps the next person looking for how to use MyMail.

Best Regards,
Paul
May 31 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.