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
 
Hi there

Try:- DoCmd.SendObject acReport, stDocName, , "user@Domain.com", , , "Test", "This is a Test",False

Tony
 
Also if you include an OutPut format it won't ask you to specify that before the mail is sent e.g.
Code:
DoCmd.SendObject acReport, stDocName,[red]"HTML"[/red], "user@Domain.com", , , "Test", "This is a Test",False

You will also now get the (rather annoying) Outlook security box for your users to click...

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
Harleyquinn is correct.

However I researched this months ago and found the following bit of freeware at:


called "Express ClickYes" which my users have been using for 6 months without conflicts or problems. It runs in background and obligingly clicks the "Yes" button whenever the Outlook Security box appears.

Only useful ideas!

Tony
 
ClickYes is a useful program. However if used in a business environment it can be (and has been by my company) classed as a potential security risk. This is because it does what it says on the tin basically, it clicks yes to dialog boxes that appear on the screen.

Cheers

Harleyquinn

---------------------------------
For tsunami relief donations
 
I'll be honest, I was not against using ClickYes (I have in several programs) by opening it in code and then closing it on the close of the application by killing the ClickYes process id (also in code). As long as it is used properly by the users that is fine. However, users are inevitably users...

Harleyquinn

---------------------------------
For tsunami relief donations
 
Many Many thanks for your replies. I have been on to the web site you suggested and see what you can insert the code to enable the clickyes. Where would I need to post this, again please excuses my ignorance, I'm still learning.

Chunk22
 
Hi there

Open a module or start a new module in Access. Enter the following exactly:-

Code:
Private Declare Function RegisterWindowMessage _
        Lib "user32" Alias "RegisterWindowMessageA" _
        (ByVal lpString As String) As Long

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

Private Declare Function SendMessage Lib "user32" _
        Alias "SendMessageA" (ByVal hwnd As Long, _
        ByVal wMsg As Long, ByVal wParam As Long, _
        lParam As Any) As Long

Now change your code to include the enable ClickYes before you send the email and then disable it once sent.

Code:
Private Sub cmdSend_Click()
Dim wnd As Long
Dim uClickYes As Long
Dim Res As Long
On Error GoTo Err_cmdSend_Click

uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME")

' Find ClickYes Window by classname
wnd = FindWindow("EXCLICKYES_WND", 0&)

' Send the message to Resume ClickYes
Res = SendMessage(wnd, uClickYes, 1, 0)

    Dim stDocName As String

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

' Send the message to Suspend ClickYes
Res = SendMessage(wnd, uClickYes, 0, 0)
    
Exit_cmdSend_Click:
    Exit Sub

Err_cmdSend_Click:
    MsgBox Err.Description
    Resume Exit_cmdSend_Click]

End Sub

This should produce the result you want! Let me know how you get on.

Just ideas!

Regards

Tony



 
You can also use sendkeys to send the keys ALT + S to send the email when it appears onscreen, this works rather well and isn't visible most of the time!

HTH

Toby
 
I have just seen an error in my code above. It was:-

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

It should be:-

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

Regards

Tony

 
I have tried the above and it returns nothing, no action is carried out. I added a watch to the cmdSend() function and it 'can't compile module' any further ideas?

Chunk22
 
Paste the code (excluding the private sub... and end sub line into the event procedure of a command button on your form. That should do the trick for you.

Cheers

Harleyquinn

---------------------------------
For tsunami relief donations
 
So are you saying that first I need to have the code as follows:

'Private Sub cmdSend_Click()- Not included

Dim wnd As Long
Dim uClickYes As Long
Dim Res As Long
On Error GoTo Err_cmdSend_Click

uClickYes = RegisterWindowMessage("CLICKYES_SUSPEND_RESUME")

' Find ClickYes Window by classname
wnd = FindWindow("EXCLICKYES_WND", 0&)

' Send the message to Resume ClickYes
Res = SendMessage(wnd, uClickYes, 1, 0)

Dim stDocName As String

stDocName = "Skateboarders_rpt"
DoCmd.SendObject acReport, stDocName, ".rtf", "ccampbell@theoracle.com", , , "Test", "This is a Test", False

' Send the message to Suspend ClickYes
Res = SendMessage(wnd, uClickYes, 0, 0)

Exit_cmdSend_Click:
Exit Sub

Err_cmdSend_Click:
MsgBox Err.Description
Resume Exit_cmdSend_Click
'End Sub - Not included

And also have the software running?

I'm a little confussed?
 
Create a button on your form called Command1.
Go to the event procedure for the click event of command1.
It will look like this in the code window
Code:
Private Sub Command1_Click
End Sub
Paste the code you now have (excluding the bits you have marked as - Not Included).
Start your program.
Start ClickYes.
Click Command1 on your form. See what happens.

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top