473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with e-mailing from within Access

Sorry, me again! I picked up the following very useful-looking bit of code from this site somewhere a while back. Now having need of something like it I decided to try it out. I can fully understand what it's doing, and so expected that it would work. But it hit a problem. The code is ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.  
  3. 'First, make sure that you have a Reference set to the
  4. 'Microsoft Outlook XX.X Object Library.
  5. 'Assuming you have a Table named tblEMailAddress, and it contains
  6. 'a Field to hold the E-Mail Addresses named [EAddr] :
  7.  
  8. Dim strEMail As String
  9. Dim oOutlook As Object
  10. Dim oMail As Object
  11. Dim strAddr As String
  12. Dim MyDB As DAO.Database
  13. Dim rstEMail As DAO.Recordset
  14.  
  15. Set oOutlook = CreateObject("Outlook.Application")
  16. Set oMail = oOutlook.CreateItem(0)
  17.  
  18. 'Retrieve all E-Mail Addressess in tblEMailAddress
  19. Set MyDB = CurrentDb
  20. Set rstEMail = MyDB.OpenRecordset("TEST_EMAIL_TBL", dbOpenSnapshot, dbOpenForwardOnly)
  21.  
  22. With rstEMail
  23.   Do While Not .EOF
  24.     'Build the Recipients String
  25.     strEMail = strEMail & ![EAddr] & ";"
  26.       .MoveNext
  27.   Loop
  28. End With
  29. '--------------------------------------------------
  30.  
  31. With oMail
  32.   .To = Left$(strEMail, Len(strEMail) - 1)        'Remove Trailing ;
  33.   .Body = "Test E-Mail to Multiple Recipients"
  34.   .Subject = "Yada, Yada, Yada"
  35.   .Send         'code halts here with error message
  36. End With
  37.  
  38. Set oMail = Nothing
  39. Set oOutlook = Nothing
  40.  
  41. rstEMail.Close
  42. Set rstEMail = Nothing
  43.  
  44. End Sub
  45.  
I have set a reference to the Outlook 12.0 object library, as per the initial comment.

The code halts at the line .Send, with the message "Application defined or Object defined error" which, in this case, presumably means Outlook doesn't like it.

Can anyone help me out with this?
Feb 28 '10 #1
4 1834
ADezii
8,834 Expert 8TB
I recognize the code quite well, and it works fine. It must be something very simple that you are missing, so I sent an Attachment to point you in the right direction. Simple fill in a valid E-Mail Address or two in the [EAddr] Field of tblEMailAddress, then fire away.
Attached Files
File Type: zip EMail.zip (14.9 KB, 95 views)
Feb 28 '10 #2
Thank you. The long delay in replying to your kind help has been caused by my attempts to find out what I did/didn't do which you didn't/did do!

The mystery is not resolved!
Your code works, my code is exactly the same as yours except my .Body and .Send are capitalised and yours are not. Thinking this could not possibly make a difference, I tried to change my .Send to .send (try anything once!) but Access won't let me, it just recapitalises it. ... And my code still doesn't work!!!

I have checked the References, and note that your code doesn't actually have a ref to the Outlook 12.0 OL. I tried matching my code's refs exactly to yours, but it made no difference. Still getting same message at same line.

If I run your code in your form, it works. If I paste it into a button on my form, it doesn't???

I'm generally having a bad Microsoft Day! I won't bore you with the rest!
Mar 1 '10 #3
ADezii
8,834 Expert 8TB
Two things, Juliet:
  1. Replace .Send with .Display and see if if works. This will display the Outlook Window and you will manually have to Send.
  2. Upload the Database with the code so we can have a look at it.
  3. There is also a chance that Outlook may have some Security Mechanism in effect to prevent the automatic Sending of E-Mails.
  4. As far as capitalization goes, I doubt very much as to whether or not it would make any difference.
  5. You actually do not need a Reference to Outlok due to Late Binding.
Mar 1 '10 #4
Thank you.
1. Yes, that makes it work. I imagine this is most useful/reassuring way for user, anyway ... so they can see the message and really know it's gone!
2. I want to send you a little zipped db, but I'm not sure I've actually managed to attach it! It is strange, too.
3. I don't think this can be so, as it sent the message fine from your little form.
4. I'm sure it wouldn't make any difference! You know how it is when you are casting about for things to try!
5. I need to research the implications of late binding (generally)

Why (2) is strange ... I just added another button to your form with my code behind it. Now neither your button nor mine works unless I replace .send with .Display. Blurrrgh!

Meanwhile, another very strange thing maybe you can shed light on.

I have also tried using .SendObject to semi-automate the sending of an individual e-mail as per the following

Private Sub EBut_Click()
Dim jb As String
jb = "j.brown265@btinternet.com"
DoCmd.SendObject , , , jb, jb, jb, "Test message", "I am testing something", True
End Sub

This displays correctly ... a mail message with jb as the recipient, cc and bcc, the subject "Test Message" and body "I'm testing something" ... and the True makes it display the thing for editing before it goes off.

BUT, very strangely, it doesn't open the message in Outlook, but in my old Yahoo mail program that is still on the system but is not my default mail program any more (because, ironically enough, I couldn't get Access to talk to it!)
Attached Files
File Type: zip EMail2.zip (26.9 KB, 81 views)
Mar 1 '10 #5

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

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
0
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent...
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.