Question : Email through VBA, using sendkeys

Hi
I'm currently trying to automate sending an email through Access 2003 using VBA. I first created an Outlook mail object, and used the .send function, but this was giving me the security dialog. I then tried using the sendkeys method to pass Alt and "S" to send the message. This works, but if the desktop is locked it won't. I assume i cannot pass a keyboard input to the locked desktop...
Has anyone any ideas of a workaround?
Leaving the desktop unlocked is not an option...
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Public Sub autoEmail(address As String, message As String)
    
    Dim olappa As Object
    Dim oitem As Object
    
    Set olappa = CreateObject("Outlook.Application")
    Set oitem = olappa.createitem(0)
    With oitem
        .subject = "subject"
        .to = address
        .body = message   
        .NoAging = True
        .Display
      End With
    Set olappa = Nothing
    Set oitem = Nothing
        SendKeys "%{s}", True
End Sub

Answer : Email through VBA, using sendkeys

Why not use CDO for sending email?

I've implemented it before but don't have access to that code at the moment. Try this link:

http://www.rondebruin.nl/cdo.htm

There are also ways to prevent the security dialog. See:
http://www.outlookcode.com/article.aspx?ID=52
and
http://msdn.microsoft.com/en-us/library/aa168346%28office.11%29.aspx
and
 "This article solution:  If using Outlook 2003, the VBA code stored inside of the VBA Project of Outlook is assumed to be "Trusted" - this then bypasses the warning messages - then you can call this VBA code using automation of Outlook. "
http://www.everythingaccess.com/tutorials.asp?ID=Outlook-Send-E-mail-Without-Security-Warning

The last link may be your best one, if you are able to access the Outlook VBA environment. Not so useful if you want lots of users to be able to send email as it requires a per-client Outlook VBA routine.

Simon
Random Solutions  
 
programming4us programming4us