Email fro FORM

  • Thread starter khashid via AccessMonster.com
  • Start date
K

khashid via AccessMonster.com

Hi All, I need assistance with the following code am using to send an email
from my form.

rivate Sub Command21_Click()
Dim SendTo As String, MySubject As String, MyMessage As String
SendTo = Me.
MySubject = "New Complain"
MyMessage = Me.Complaint_No & vbCr & Me.Complaint_Type & vbCr & Me.CSR & vbCr
& Me.Customer_Name & vbCr & Me.Card_No & vbCr & Me.Card_Type & vbCr & Me.
CC_Department & vbCr & Me.Complaint

DoCmd.SendObject acSendNoObject, , , SendTo, , , MySubject, MyMessage, True

I need few changes if you can help.
1- Send CC copy
2- MySubject, i want to have the Complain No in the subject in this format
Complain No : [Complain_No]
3- In the MyMessage I want to have the headings with the information because
right now its kindof difficult to figure out the information. I want it this
way
Complain No: [Complain_No]
Customer Name: [Customer_name]
etc....
4- I want the email sent directly as soon the user hits send, right now it
stops for editing.
 
D

Daniel

You'll need to learn to start using the help a bit more. It covers the
parameters for the sendobject method in detail.

based on the help file we can get the base synthax for this method which is

expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc,
Subject, MessageText, EditMessage, TemplateFile)

1. so to add a Cc recipient you need only add a 5th variable to your coding
2. We need only concateneate the info on the form into a single string
3. Simple string manip.
4. is controled by the EditMessage boolean value

i. you should start calling you buttons by real names and not the default
values (this will simplify your life when reviewing your code at a later
date, trust me!!!).

Private Sub Command21_Click()
Dim SendTo As String
Dim SendCc As String
Dim MySubject As String
Dim MyMessage As String


SendTo = Me.
SendCc = "CcRecipientEmailAddressGoesHere"
MySubject = "Complain No :" & Me.[Complain_No]
MyMessage = "Complain No:" & Me.[Complain_No] & vbcrlf & "Customer Name:" &
Me.[Customer_name]

DoCmd.SendObject acSendNoObject, , , SendTo,SendCc , , MySubject, MyMessage,
False

End Sub
 
K

khashid via AccessMonster.com

Thanks very much, trust me i love to go through the help files and it always
help me out but at this moment i really didnt have time to do that.

It worked fine thanks again for your help. One last thing if u dont mind
helping me out is when the email is ready if i cancel the email it gives a
run time error that email was canceled and ask to debug
. How can I have some other error so it would not ask for debug or just
simply not to have error
Daniel said:
You'll need to learn to start using the help a bit more. It covers the
parameters for the sendobject method in detail.

based on the help file we can get the base synthax for this method which is

expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc,
Subject, MessageText, EditMessage, TemplateFile)

1. so to add a Cc recipient you need only add a 5th variable to your coding
2. We need only concateneate the info on the form into a single string
3. Simple string manip.
4. is controled by the EditMessage boolean value

i. you should start calling you buttons by real names and not the default
values (this will simplify your life when reviewing your code at a later
date, trust me!!!).

Private Sub Command21_Click()
Dim SendTo As String
Dim SendCc As String
Dim MySubject As String
Dim MyMessage As String

SendTo = Me.
SendCc = "CcRecipientEmailAddressGoesHere"
MySubject = "Complain No :" & Me.[Complain_No]
MyMessage = "Complain No:" & Me.[Complain_No] & vbcrlf & "Customer Name:" &
Me.[Customer_name]

DoCmd.SendObject acSendNoObject, , , SendTo,SendCc , , MySubject, MyMessage,
False

End Sub[QUOTE]
Hi All, I need assistance with the following code am using to send an email
from my form.[/QUOTE]
[quoted text clipped - 21 lines][QUOTE]
4- I want the email sent directly as soon the user hits send, right now it
stops for editing.[/QUOTE][/QUOTE]
 
D

Daniel

This is called error handling. you need to put in place error handling in
your code (you should do this by default in all your functions...)

Try somthing like the following
Private Sub Command21_Click()
On Error GoTo Command21_Click_Error
Dim SendTo As String
Dim SendCc As String
Dim MySubject As String
Dim MyMessage As String

SendTo = Me.
SendCc = "CcRecipientEmailAddressGoesHere"
MySubject = "Complain No :" & Me.[Complain_No]
MyMessage = "Complain No:" & Me.[Complain_No] & vbCrLf & "Customer Name:" & _
Me.[Customer_name]

DoCmd.SendObject acSendNoObject, , , SendTo, SendCc, , MySubject, MyMessage,
False

Command21_Click_Error:
If Err.Number = 55 Then
'Nothing need to be done
ElseIf Err.Number <> 0 And Err.Number <> 55 Then
MsgBox "MS Access has generated the following error" & vbCrLf &
vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: Command21_Click" & vbCrLf & _
"Error Description: " & Err.Description, vbCritical, "An Error has
Occured!"
End If
Exit Sub
End Sub

I used err.number 55 (just as an example) but you'll need to enter the
errornumber you are getting.
--
Hope this helps,

Daniel P





[QUOTE="khashid via AccessMonster.com"]
Thanks very much, trust me i love to go through the help files and it always
help me out but at this moment i really didnt have time to do that.

It worked fine thanks again for your help. One last thing if u dont mind
helping me out is when the email is ready if i cancel the email it gives a
run time error that email was canceled and ask to debug
. How can I have some other error so it would not ask for debug or just
simply not to have error
[QUOTE="Daniel"]
You'll need to learn to start using the help a bit more. It covers the
parameters for the sendobject method in detail.

based on the help file we can get the base synthax for this method which is

expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc,
Subject, MessageText, EditMessage, TemplateFile)

1. so to add a Cc recipient you need only add a 5th variable to your coding
2. We need only concateneate the info on the form into a single string
3. Simple string manip.
4. is controled by the EditMessage boolean value

i. you should start calling you buttons by real names and not the default
values (this will simplify your life when reviewing your code at a later
date, trust me!!!).

Private Sub Command21_Click()
Dim SendTo As String
Dim SendCc As String
Dim MySubject As String
Dim MyMessage As String

SendTo = Me.[Email]
SendCc = "CcRecipientEmailAddressGoesHere"
MySubject = "Complain No :" & Me.[Complain_No]
MyMessage = "Complain No:" & Me.[Complain_No] & vbcrlf & "Customer Name:" &
Me.[Customer_name]

DoCmd.SendObject acSendNoObject, , , SendTo,SendCc , , MySubject, MyMessage,
False

End Sub[QUOTE]
Hi All, I need assistance with the following code am using to send an email
from my form.[/QUOTE]
[quoted text clipped - 21 lines][QUOTE]
4- I want the email sent directly as soon the user hits send, right now it
stops for editing.[/QUOTE][/QUOTE]
[/QUOTE]
 
G

Gary Dolliver

Hello Daniel,
I am hoping you may be able to assist me as well. I have been going through
the help files and all of these forums and I am stumped on how to set up a
"sendfrom" line. I am needing this as I will have different emails being
sent from different sections of the program (currently, it will only send
from the default email of Outlook). I would like certain emails to come from
"customer service" and others from "order confirmation" depending on where
the email is being sent from in the program.
Hope you can help and thanks for your time.
-gary

Daniel said:
This is called error handling. you need to put in place error handling in
your code (you should do this by default in all your functions...)

Try somthing like the following
Private Sub Command21_Click()
On Error GoTo Command21_Click_Error
Dim SendTo As String
Dim SendCc As String
Dim MySubject As String
Dim MyMessage As String

SendTo = Me.
SendCc = "CcRecipientEmailAddressGoesHere"
MySubject = "Complain No :" & Me.[Complain_No]
MyMessage = "Complain No:" & Me.[Complain_No] & vbCrLf & "Customer Name:" & _
Me.[Customer_name]

DoCmd.SendObject acSendNoObject, , , SendTo, SendCc, , MySubject, MyMessage,
False

Command21_Click_Error:
If Err.Number = 55 Then
'Nothing need to be done
ElseIf Err.Number <> 0 And Err.Number <> 55 Then
MsgBox "MS Access has generated the following error" & vbCrLf &
vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: Command21_Click" & vbCrLf & _
"Error Description: " & Err.Description, vbCritical, "An Error has
Occured!"
End If
Exit Sub
End Sub

I used err.number 55 (just as an example) but you'll need to enter the
errornumber you are getting.
--
Hope this helps,

Daniel P





[QUOTE="khashid via AccessMonster.com"]
Thanks very much, trust me i love to go through the help files and it always
help me out but at this moment i really didnt have time to do that.

It worked fine thanks again for your help. One last thing if u dont mind
helping me out is when the email is ready if i cancel the email it gives a
run time error that email was canceled and ask to debug
. How can I have some other error so it would not ask for debug or just
simply not to have error
[QUOTE="Daniel"]
You'll need to learn to start using the help a bit more. It covers the
parameters for the sendobject method in detail.

based on the help file we can get the base synthax for this method which is

expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc,
Subject, MessageText, EditMessage, TemplateFile)

1. so to add a Cc recipient you need only add a 5th variable to your coding
2. We need only concateneate the info on the form into a single string
3. Simple string manip.
4. is controled by the EditMessage boolean value

i. you should start calling you buttons by real names and not the default
values (this will simplify your life when reviewing your code at a later
date, trust me!!!).

Private Sub Command21_Click()
Dim SendTo As String
Dim SendCc As String
Dim MySubject As String
Dim MyMessage As String

SendTo = Me.[Email]
SendCc = "CcRecipientEmailAddressGoesHere"
MySubject = "Complain No :" & Me.[Complain_No]
MyMessage = "Complain No:" & Me.[Complain_No] & vbcrlf & "Customer Name:" &
Me.[Customer_name]

DoCmd.SendObject acSendNoObject, , , SendTo,SendCc , , MySubject, MyMessage,
False

End Sub
Hi All, I need assistance with the following code am using to send an email
from my form.
[quoted text clipped - 21 lines]
4- I want the email sent directly as soon the user hits send, right now it
stops for editing.[/QUOTE]
[/QUOTE][/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SendObject Email 2
Email Issue 1
Email issue 0
BCC Email 3
Email problem 5
Emailing with field name in body of email 7
Emailing information about a specific record 4
Error on sending email 2

Top