SendObject

Rob.Mills

Registered User.
Local time
Today, 14:39
Joined
Aug 29, 2002
Messages
871
This is a second try to get a solution for this challenge. I've got my coded listed below. What I've got is a continuous form that has an email address in the first field. I've set it up so that when I double-click on the field it will open an email while inserting certain info in the message. Now the first time i run this procedure it works great. BUT when I try to run the procedure on another record nothing happens. I have to close the db and reopen it to make it work on another record.

Any thoughts as to why?



Public Function Email()

On Error GoTo Err_Email

Dim strTo As String, strMsg As String, strSubject As String

strTo = Me!txtRequestor.Value & "@hotmail.com"
strSubject = "Completed Request"
strMsg = Me!txtPayee & " in " & Me!txtCounty & " county, " & Me!txtState & " is completed."

DoCmd.SendObject acSendNoObject, , , strTo, , , strSubject, strMsg, True

Exit Function

Err_Email:
If Err.Number = 2501 Then
Exit Function
Else
MsgBox Err.Number & " " & Err.Description
Exit Function
End If
End Function
 
Reply to send emails

Private Sub cmdSendMail_Click()
Dim rsEmail As DAO.Recordset
Dim strEmail As String


Set rsEmail = CurrentDb.OpenRecordset("EmailList")

Do While Not rsEmail.EOF
strEmail = rsEmail.Fields("EmailAddress").Value
DoCmd.SendObject , , , strEmail, , , "Test 3", "Hi", False
rsEmail.MoveNext

Loop
Set rsEmail = Nothing
MsgBox "Emails have been sent"

End Sub

This subroutine works evrytime. If you want to be able to edit the emails before you send them replace the false with true.

Maria

Ps if this doesn't answer your question be more specific and I'll try to help.

Maria
 
Well I do need it to loop through the table. I've got a list of tasks for myself and as I complete things I want to be able to email the person that requested it. So all I want it to do is open an email addressed to the person that is in the record where I double click.

Now the first time I do this after opening the db it works great. But if I move down the list and try it on another record nothing happens. No rhyme or reason to this other than the fact that it will only let me run the procedure once while I have the db open.
 
Have I actually found a challenge to stump everyone? I haven't found any solution to this one.

If you know how to fix this, PLEASE, let me know.
 
Have you tried running your sendobject program as a vba procedure instead of a function call when you double click
the e-mail field?

I think this will work, although I have not tried it.

edtab
 
Rob,
I have almost identical code in a continuous form and it works fine.

Seems odd that it doesn't do anything at all. Have you tried stepping through the code to see what is happening?

Dave
 
Rob - The problem is with the sendobject command and has been verified by Microsoft. You can read more about it at:http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q260819&

I had the same problem - the first email was always sent and then nothing not even an error message.

I had to change from Exchange to Outlook to get away from using the sendobject command.

Paul.

if you're using Outlook, try something like this...

Dim rsemail As DAO.Recordset
Dim strEmail As String
Dim objOutlookAttach As Outlook.Attachment
Dim objOutlook As Outlook.Application

Set rsemail = Me.Recordset

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
strEmail = rsemail.Fields("email").Value

With objOutlookMsg
.to = strEmail
.Subject = "subject test”
.Body = "message goes here"
.Send
End With

Set objOutlook = Nothing
Set rsemail = Nothing
 
Paul - That did it! Thank you very much!

Out of curiousity, do you know if you can do something similar using Outlook Express. I'm setting up a db at home and would like to be able to send from there as well.
 

Users who are viewing this thread

Back
Top Bottom