troubleshooting Question

Email through VBA, using sendkeys

Avatar of ITUCIRL
ITUCIRL asked on
Microsoft Access
8 Comments2 Solutions3559 ViewsLast Modified:
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...
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
      End With
    Set olappa = Nothing
    Set oitem = Nothing
        SendKeys "%{s}", True
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros