DoCmd.SendObject used in multiple email buttons

duthiedon

Donner
Local time
Today, 14:43
Joined
Dec 27, 2007
Messages
60
Have found some code that originated from this forum, and have modified it to suit my needs. There's one form with all the information, that has multiple buttons and subsequently multiple functions to generate emails, with each button/email to generate a different format and content. The first use of a button works fine, but trying to use the next button right after does nothing. If you exit the form and re-enter, you can then use the next email button, but that's a pain and the users won't like that. Can anyone help? I've pasted a sample of the code that is being used below, it's duplicated and changed slightly for the other buttons. I currently have the button linked to a macro that does other things like saving, and setting dates and then running the function.

Thanks,
Don
-----------------------------------------------------------------
Public Function AckEmailNew()
On Error GoTo Err_cmdMailTicket_Click

Dim varTo As String '-- Address for SendObject
Dim stText As String '-- E-mail text
Dim stSubject As String '-- Subject line of e-mail
Dim stTicketID As String '-- The ticket ID from form
Dim strSQL As String '-- Create SQL update statement
Dim errLoop As Error

varTo = Me.ClientEmail
stTicketID = Me.STSITicket

stSubject = "Ticket/numéro de référence: " & stTicketID


stText = <<My text goes here>>

'Write the e-mail content for sending to assignee
DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1

On Error GoTo Err_Execute

Exit Function

Err_Execute:

MsgBox Err.Description
Resume Exit_cmdMailTicket_Click

Exit_cmdMailTicket_Click:
Exit Function

Err_cmdMailTicket_Click:
MsgBox Err.Description
Resume Exit_cmdMailTicket_Click

End Function
 
The commands all work from home where I use MS Office XP and Outlook resides on my desktop. At work, we use MS Access 2000 but with MS Outlook 2003. Bit puzzled and perplexed on how to get this working.
 
Might I suggest you have only one button and then have a couple of option boxes on your form (one for format, one for content). Then you only need one button and hence one set of code. One set of code means easy to debug and easy to maintain.

For the format you could easily set up a 2 column combo (e.g. called emailFormat) with the Access defined formats in the first column and the description that the users sees in the 2nd column (then hide the 1st col from the user). Replace your email line with:

DoCmd.SendObject , , Me.emailFormat, varTo, , , stSubject, stText, -1

Another tip... Unless you're planning to use this code in other forms then don't create a public function for it. Just put it in the "On Click" code area for the button.

It's difficult to answer your problem specifically as we can't see how you've set up your macros etc. If you need more help then it might be worth posting your d/b.

Chris
 
Thanks for the advice, unfortunately they want each button to generate the email automatically - hence multiple buttons, because they pull up different info and different content. There's a total of 6 email buttons. I did take your advice and put the entire code as part of the button as opposed to running a public function and macros. No idea why, but now I can generate 2 emails consecutively, but then it stops and the only way to reset is to exit the database and then continue. I've included the full code that I'm now using below:

Private Sub Command62_Click()
On Error GoTo Err_Command62_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Me.ACKSent = Date

Dim varTo As String '-- Address for SendObject
Dim stText As String '-- E-mail text
Dim stSubject As String '-- Subject line of e-mail
Dim stTicketID As String '-- The ticket ID from form

varTo = Me.ClientEmail
stTicketID = Me.STSITicket

stSubject = "Ticket/numéro de référence: " & stTicketID


stText = "Good morning/afternoon, " & Chr$(13) & _
"Thank you for your recent email/phone call. The issue/question raised is now " & _
"under investigation and assigned ticket number " & stTicketID & _
". XXXXXX will contact you with a reply as soon as possible." & Chr$(13) & _
Chr$(13) & _
" XXXXXX" & Chr$(13) & _
" XXXXXXX" & Chr$(13) & _
" ------------------------------------------------------------------------------"
'Write the e-mail content for sending to assignee
DoCmd.SendObject , , , varTo, , , stSubject, stText, -1


Exit_Command62_Click:
Exit Sub

Err_Command62_Click:
MsgBox Err.Description
Resume Exit_Command62_Click

End Sub
 
The fact that it works with XP and not 2000 reminds me that there were some SendObject issues with 2000. Make sure you've got all the service packs applied to the 2000 PC, as one of them may have addressed this problem.
 
Thanks very much for the advice, I finally got it to work and it was related to issues with Office 2000.
 

Users who are viewing this thread

Back
Top Bottom