Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automated e-mailing 2

Status
Not open for further replies.

chunk22

IS-IT--Management
Mar 5, 2005
23
GB
I apologise for being the novice that I am, I have only been using Access and VBA for a few month. I have a database that needs a report to be e-mailed out automatically, without the user have to click send.

I have Outlook 2003 / Exchange and Access 2003. I have managed to get the e-mail to open but I would like it to send automatically. Please see code below, can anyone help?

[Private Sub cmdSend_Click()
On Error GoTo Err_cmdSend_Click

Dim stDocName As String

stDocName = "Skateboarders_rpt"
DoCmd.SendObject acReport, stDocName, , "user@Domain.com", , , "Test", "This is a Test"

Exit_cmdSend_Click:
Exit Sub

Err_cmdSend_Click:
MsgBox Err.Description
Resume Exit_cmdSend_Click]

Thanks

Chunk22
 
ClickYes automatically looks for the Outlook Security window and when it appears it clicks the Yes button so you don't have to. Looking for the window can be enabled or disabled but only when ClickYes is running. This is the purpose of the new code round your original code.

Hope this makes sense!

Tony
 
Thanks for your help, I have done that and I get an error again with the following line:

uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME")

Any further sugestions?

Thanks again

Chunk22
 
Have you entered the declarations in an access module and recompiled the code?

Tony
 
What I have done is put the API decs in a module called Module 1

Chunk22
 
Sorry - if you put the declarations in a module then you must remove the word "Private" from the start of the three declarations. So it should be:-
Code:
Declare Function RegisterWindowMessage _
        Lib "user32" Alias "RegisterWindowMessageA" _
        (ByVal lpString As String) As Long

Declare Function FindWindow Lib "user32" _
        Alias "FindWindowA" (ByVal lpClassName As Any, _
        ByVal lpWindowName As Any) As Long

Declare Function SendMessage Lib "user32" _
        Alias "SendMessageA" (ByVal hwnd As Long, _
        ByVal wMsg As Long, ByVal wParam As Long, _
        lParam As Any) As Long
 
That now loads but you have to click 'yes' to get rid of the window.

In the error handling it says "Expression not defined in context" (Watch on "cmdSend_Click()

Any suggestions?

 
You should have the ClickYes icon in your system tray at the bottom right of your screen. Click on the icon with your right hand mouse button and select "Suspend". It should now have a red cross on the icon. Also select "Start Suspended" so it defaults to suspended on startup. Now when you run your code by clicking "cmdsend" button, it enables ClickYes, sends your email, and then disables it again.

Regards

Tony
 
Many many thanks for your assistants all.

Chunk22
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top