|
-
Dec 14th, 2003, 03:27 PM
#1
Thread Starter
New Member
Send an Email by clicking a button
Hi, hope you can help me here I'm pulling my hair out with what i thought would be a simple matter.
I have a small acccess project that i want to automate as much as possible for the end user. So far it's been pretty straight forward. The latest hurdle i've come accross is being able to send an external file as an attatchment to an email recipient. I've had a look at the sendobject cmd but this only appears to work with (1) database objects, ie forms, reports etc and not external files. (2) unless the email to address is in the email programs address book i seem to get an error.
Someone suggested using mapi, someone else suggested CDO but thats as much information as they gave me. Ive tried with both but keep coming up with errors which i dont entirely understand (mainly because i aint a programmer and i'm trying to pick things up as i go along), the main thrust of the errors was that objects where required - i've added refernces to both mapi and CDO in the references bit and i can see the objects in the browser but i well and truly stuck.
Some gentle guidance and patience would be greatly appreciated.
Regards,
Noel.
-
Dec 14th, 2003, 04:04 PM
#2
To send an email you can use the below code.
VB Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
Private Sub Label2_Click()
ShellExecute Me.hwnd, vbNullString, "mailto: [email protected]", vbNullString, "C:", SW_SHOWNORMAL
End Sub
-
Dec 14th, 2003, 04:55 PM
#3
Thread Starter
New Member
Thanks for your quick response lintz.
I've put your code in and sure enough it kicks off and email. Woohoo..
But, would you mind giving me a little explanation of your code and explaining how i can adapt it for my needs. ie it needs to include a file attactment and it also needs to pick up the "to address" from a table (via a combo box on the active form).
Regards,
Noel.
**Update**
I've worked out how to put the address in as desired so it's just a little help on the attactment if you would.
Thanks.
Last edited by Apollo14; Dec 14th, 2003 at 05:03 PM.
-
Dec 15th, 2003, 03:40 AM
#4
I think this should work if you're using Outlook. I haven't tested this code as I haven't got Outlook installed on this machine.
VB Code:
Dim myAttachment As outlook.Attachments
Set myAttachment = olMail.Attachments
myAttachment.Add "PathToAttachment"
-
Dec 15th, 2003, 02:12 PM
#5
Thread Starter
New Member
Hi Lintz,
Just got home and tried adding the statement that you gave and i get an error message saying user defined type not defined. I tried type checking it too and after typing outlook. i didnt get the selection that usually appears with recognised object types.
Regards,
Noel.
-
Dec 15th, 2003, 11:43 PM
#6
I've tested this and it works. Make sure you add a reference to Outlook otherwise you'll get errors.
VB Code:
Dim olMail As Outlook.MailItem
Dim olapp As New Outlook.Application
Dim myAttachment As Outlook.Attachments
Set olMail = olapp.CreateItem(olMailItem)
Set myAttachment = olMail.Attachments
myAttachment.Add "PathToAttachment"
olMail.Send
-
Dec 16th, 2003, 11:26 AM
#7
Thread Starter
New Member
Hi Lintz thanks for your help so far.
Perhaps i should have mentioned that i dont have outlook installed on my machine - only outlook express. This is because the end project is going out to a user who has only had a basic OS installation done on their PC.
Is there anyway to use outlook express? I've been doing loads of digging around and have come to the conclusion that it will probly have to be done through CDO.
I've added refernces to CDO and have tried something like;
dim Mymsg as cdo.messsage
mymsg.to = "toaddress"
mymsg.from = "fromaddress"
mymsg.send
When i try to run the routine i get nothing at all. no errors, no email, nothing.
Any ideas?
Regards,
Noel.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|