SendObject function to send email

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got a form that collects a little information about employee's. What I
want the form to do is once it's been filled out and they click the "save and
close" button, I want it to automatically send an email to the address in the
email field. I've got this mostly working except for a couple things. I
want the message body to contain more that just 256 characters and for some
reason the template field doesn't seem to do anything. I created a template
in .html format and put the path in the appropriate field but none of it
appears in the email. Am I doing something wrong? thanks.
 
Not sure what you mean by the template field. Also, I don't know how you are
doing this, so it is hard to know what is going wrong wrong. Are you
attempting to embed something from the database into the body of an html
e-mail message, or are you sending an attachment, or something else? Are you
using SendObject? If not, see Help for details. It may do what you need.
 
I've added a button to the form and created a macro to run with the onclick
event. In the macro I'm using the sendobject action. Down in the Action
Arguments pane there's a Template File field. In the help section on the
right it says, "Enter the full path of the file to use as a template for your
output. This argument only applies to HTML formats. Leave blank to use no
template. Press F1 for help on this action."

In help, all it says about this argument is, "The path and file name of a
file you want to use as a template for an .html file. The template file is a
file containing HTML tags."

Does this mean that I can only use the Template File action argument if I
only intend to use the SendObject action to create a "webpage" based off a
template? If that's the case, that's not at all what I want to do.

I just want to send an email to the person whom we've just created a new
record for that contains instructions on how to access the database. But I'd
rather these instructions be in the body of the message rather than as an
attachment.

I'm this has got to be possible in code, but I've got to be the worst
programmer on the face of this planet. :(
 
You could do something like this with SendObject:

Docmd.SendObject acSendNoObject, , ,"(e-mail address removed)", , , "Subject","Go
here to open database"

That's all on one line in the code window, by the way.
I couldn't tell you about the template file part of the code, but I suspect
it has to do with using Access on the web. If all you need to do is send a
text message, something like the code above should do the trick. Substitute
control names for any item as needed. For instance, if the e-mail address is
in txtEmail on the form, the e-mail address in the code would be
Me![txtEmail]. If the message is standard for all recipients it could be
contained in a text box (hidden, if you like) on the form, or even in another
table. How you reference it in the code depends on the details of what you
need to do. Even if you could come up with at html e-mail I don't think you
would want to, as some recipients may use plain text.
If you start typing the code in the code window it will probably suggest
options as you go. When To is highlighted you would enter the information
for the To line of your e-mail message, etc. You need the empty commas as
space holders for things you are not including, but you don't need commas at
the end.
 
Okay Bruce, I think I'm really close but I still need you to hold my hand on
this one. This is what I've added:

DoCmd.SendObject acSendNoObject, , , Me.Email, , , "Information about the
FSR Update database", Me.txtMsgBody, True

On my form I've added a text box called txtMsgBody. I made it hidden and
added the following text to the Control Source property:

**********************Begginning of Message******************

Dear Sir or Madam,

This email is intended to introduce you to the FSR Update database. In this
database you are given the opportunity to provide your contact and emergency
contact information. It also allows you to keep track of other types of
information, such as; passports, visas, vaccinations and mobility training.
You are urged to keep this information up to date. This database provides a
number of services to the field organization and is used quite frequently by
the field management.

To access this application please follow the underlying steps:

1. Login to Citrix. (If you are unfamiliar with Citrix, feel free to ask
your supervisor for help)
2. Click the FSR Update icon in the list of applications.
3. Your username is your employee number.
4. Your password by default is your date of birth. (Once you've logged in
once, you can change your password. Take note that this password is
independent of any other passwords you might have.)

If you are denied access to the database, please send an email to the field
management for help.

Thank you and welcome to the field organization!

Field Management

**************************End of Message*******************

When I click the button that runs this code, it gives me an error message
that says, "An expression you entered is the wrong data type for one of the
arguments".

How do I change the data type of the txtMsgBody text box to something like
Memo or something that will allow carriage returns and a whole bunch of
characters?

BruceM said:
You could do something like this with SendObject:

Docmd.SendObject acSendNoObject, , ,"(e-mail address removed)", , , "Subject","Go
here to open database"

That's all on one line in the code window, by the way.
I couldn't tell you about the template file part of the code, but I suspect
it has to do with using Access on the web. If all you need to do is send a
text message, something like the code above should do the trick. Substitute
control names for any item as needed. For instance, if the e-mail address is
in txtEmail on the form, the e-mail address in the code would be
Me![txtEmail]. If the message is standard for all recipients it could be
contained in a text box (hidden, if you like) on the form, or even in another
table. How you reference it in the code depends on the details of what you
need to do. Even if you could come up with at html e-mail I don't think you
would want to, as some recipients may use plain text.
If you start typing the code in the code window it will probably suggest
options as you go. When To is highlighted you would enter the information
for the To line of your e-mail message, etc. You need the empty commas as
space holders for things you are not including, but you don't need commas at
the end.

Jonathan Brown said:
I've added a button to the form and created a macro to run with the onclick
event. In the macro I'm using the sendobject action. Down in the Action
Arguments pane there's a Template File field. In the help section on the
right it says, "Enter the full path of the file to use as a template for your
output. This argument only applies to HTML formats. Leave blank to use no
template. Press F1 for help on this action."

In help, all it says about this argument is, "The path and file name of a
file you want to use as a template for an .html file. The template file is a
file containing HTML tags."

Does this mean that I can only use the Template File action argument if I
only intend to use the SendObject action to create a "webpage" based off a
template? If that's the case, that's not at all what I want to do.

I just want to send an email to the person whom we've just created a new
record for that contains instructions on how to access the database. But I'd
rather these instructions be in the body of the message rather than as an
attachment.

I'm this has got to be possible in code, but I've got to be the worst
programmer on the face of this planet. :(
 
Bruce, I figured it out!

I wasn't aware how to use vbCrLf or what it was even. It works perfectly
now. Check out the code I used:

***************beginning of code*******************
Dim objOutlook As New Outlook.Application
Dim objMail As MailItem

Set objOutlook = New Outlook.Application
Set objMail = objOutlook.CreateItem(olMailItem)

EmailAddr = Me.Email
CopyEmailAddr = ""
Subj = "Information about the FSR Update database."
Body = "Dear " & Me.FirstName & " " & Me.LastName & "," & vbCrLf & vbCrLf & _
"This email is intended to introduce you to the FSR Update database.
In this database you are given the opportunity to provide your contact and
emergency contact information. It also allows you to keep track of other
types of information, such as; passports, visas, vaccinations and mobility
training. You are urged to keep this information up to date. This database
provides a number of services to the field organization and is used quite
frequently by the field management." & vbCrLf & vbCrLf & _
"To access this application please follow the underlying steps:" &
vbCrLf & vbCrLf & _
"1. Login to Citrix. (If you are unfamiliar with Citrix, feel free
to ask your supervisor for help)" & vbCrLf & _
"2. Click the FSR Update icon in the list of applications." & vbCrLf
& _
"3. Your username is your life number." & vbCrLf & _
"4. Your password by default is your date of birth. (Once you've
logged in once, you can change your password. Take note that this password
is independent of any other passwords you might have.)" & vbCrLf & vbCrLf & _
"If you are denied access to the database, please send an email to
the field management for help." & vbCrLf & vbCrLf & _
"Thank you and welcome to the field organization!" & vbCrLf & vbCrLf
& _
"Field Management"
PathName = ""

With objMail
.To = EmailAddr
.cc = CopyEmailAddr
.Subject = Subj
.Body = Body
.NoAging = True
.Display
End With

**********************end of code*********************

I had to add the Microsoft Outlook object library to my references to use it
correctly.

Jonathan Brown said:
Okay Bruce, I think I'm really close but I still need you to hold my hand on
this one. This is what I've added:

DoCmd.SendObject acSendNoObject, , , Me.Email, , , "Information about the
FSR Update database", Me.txtMsgBody, True

On my form I've added a text box called txtMsgBody. I made it hidden and
added the following text to the Control Source property:

**********************Begginning of Message******************

Dear Sir or Madam,

This email is intended to introduce you to the FSR Update database. In this
database you are given the opportunity to provide your contact and emergency
contact information. It also allows you to keep track of other types of
information, such as; passports, visas, vaccinations and mobility training.
You are urged to keep this information up to date. This database provides a
number of services to the field organization and is used quite frequently by
the field management.

To access this application please follow the underlying steps:

1. Login to Citrix. (If you are unfamiliar with Citrix, feel free to ask
your supervisor for help)
2. Click the FSR Update icon in the list of applications.
3. Your username is your employee number.
4. Your password by default is your date of birth. (Once you've logged in
once, you can change your password. Take note that this password is
independent of any other passwords you might have.)

If you are denied access to the database, please send an email to the field
management for help.

Thank you and welcome to the field organization!

Field Management

**************************End of Message*******************

When I click the button that runs this code, it gives me an error message
that says, "An expression you entered is the wrong data type for one of the
arguments".

How do I change the data type of the txtMsgBody text box to something like
Memo or something that will allow carriage returns and a whole bunch of
characters?

BruceM said:
You could do something like this with SendObject:

Docmd.SendObject acSendNoObject, , ,"(e-mail address removed)", , , "Subject","Go
here to open database"

That's all on one line in the code window, by the way.
I couldn't tell you about the template file part of the code, but I suspect
it has to do with using Access on the web. If all you need to do is send a
text message, something like the code above should do the trick. Substitute
control names for any item as needed. For instance, if the e-mail address is
in txtEmail on the form, the e-mail address in the code would be
Me![txtEmail]. If the message is standard for all recipients it could be
contained in a text box (hidden, if you like) on the form, or even in another
table. How you reference it in the code depends on the details of what you
need to do. Even if you could come up with at html e-mail I don't think you
would want to, as some recipients may use plain text.
If you start typing the code in the code window it will probably suggest
options as you go. When To is highlighted you would enter the information
for the To line of your e-mail message, etc. You need the empty commas as
space holders for things you are not including, but you don't need commas at
the end.

Jonathan Brown said:
I've added a button to the form and created a macro to run with the onclick
event. In the macro I'm using the sendobject action. Down in the Action
Arguments pane there's a Template File field. In the help section on the
right it says, "Enter the full path of the file to use as a template for your
output. This argument only applies to HTML formats. Leave blank to use no
template. Press F1 for help on this action."

In help, all it says about this argument is, "The path and file name of a
file you want to use as a template for an .html file. The template file is a
file containing HTML tags."

Does this mean that I can only use the Template File action argument if I
only intend to use the SendObject action to create a "webpage" based off a
template? If that's the case, that's not at all what I want to do.

I just want to send an email to the person whom we've just created a new
record for that contains instructions on how to access the database. But I'd
rather these instructions be in the body of the message rather than as an
attachment.

I'm this has got to be possible in code, but I've got to be the worst
programmer on the face of this planet. :(

:

Not sure what you mean by the template field. Also, I don't know how you are
doing this, so it is hard to know what is going wrong wrong. Are you
attempting to embed something from the database into the body of an html
e-mail message, or are you sending an attachment, or something else? Are you
using SendObject? If not, see Help for details. It may do what you need.

:

I've got a form that collects a little information about employee's. What I
want the form to do is once it's been filled out and they click the "save and
close" button, I want it to automatically send an email to the address in the
email field. I've got this mostly working except for a couple things. I
want the message body to contain more that just 256 characters and for some
reason the template field doesn't seem to do anything. I created a template
in .html format and put the path in the appropriate field but none of it
appears in the email. Am I doing something wrong? thanks.
 
Cool. I hadn't known about the Access 2000 difficulty with long e-mail
messages and SendObject. I have used chr(13) and chr(10) in code, which as I
understand is the same as vbCrLf, but never for an e-mail. My use of
SendObject so far has been to open an e-mail message, with maybe something in
the Subject line. Good work figuring that one out.

Jonathan Brown said:
Bruce, I figured it out!

I wasn't aware how to use vbCrLf or what it was even. It works perfectly
now. Check out the code I used:

***************beginning of code*******************
Dim objOutlook As New Outlook.Application
Dim objMail As MailItem

Set objOutlook = New Outlook.Application
Set objMail = objOutlook.CreateItem(olMailItem)

EmailAddr = Me.Email
CopyEmailAddr = ""
Subj = "Information about the FSR Update database."
Body = "Dear " & Me.FirstName & " " & Me.LastName & "," & vbCrLf & vbCrLf & _
"This email is intended to introduce you to the FSR Update database.
In this database you are given the opportunity to provide your contact and
emergency contact information. It also allows you to keep track of other
types of information, such as; passports, visas, vaccinations and mobility
training. You are urged to keep this information up to date. This database
provides a number of services to the field organization and is used quite
frequently by the field management." & vbCrLf & vbCrLf & _
"To access this application please follow the underlying steps:" &
vbCrLf & vbCrLf & _
"1. Login to Citrix. (If you are unfamiliar with Citrix, feel free
to ask your supervisor for help)" & vbCrLf & _
"2. Click the FSR Update icon in the list of applications." & vbCrLf
& _
"3. Your username is your life number." & vbCrLf & _
"4. Your password by default is your date of birth. (Once you've
logged in once, you can change your password. Take note that this password
is independent of any other passwords you might have.)" & vbCrLf & vbCrLf & _
"If you are denied access to the database, please send an email to
the field management for help." & vbCrLf & vbCrLf & _
"Thank you and welcome to the field organization!" & vbCrLf & vbCrLf
& _
"Field Management"
PathName = ""

With objMail
.To = EmailAddr
.cc = CopyEmailAddr
.Subject = Subj
.Body = Body
.NoAging = True
.Display
End With

**********************end of code*********************

I had to add the Microsoft Outlook object library to my references to use it
correctly.

Jonathan Brown said:
Okay Bruce, I think I'm really close but I still need you to hold my hand on
this one. This is what I've added:

DoCmd.SendObject acSendNoObject, , , Me.Email, , , "Information about the
FSR Update database", Me.txtMsgBody, True

On my form I've added a text box called txtMsgBody. I made it hidden and
added the following text to the Control Source property:

**********************Begginning of Message******************

Dear Sir or Madam,

This email is intended to introduce you to the FSR Update database. In this
database you are given the opportunity to provide your contact and emergency
contact information. It also allows you to keep track of other types of
information, such as; passports, visas, vaccinations and mobility training.
You are urged to keep this information up to date. This database provides a
number of services to the field organization and is used quite frequently by
the field management.

To access this application please follow the underlying steps:

1. Login to Citrix. (If you are unfamiliar with Citrix, feel free to ask
your supervisor for help)
2. Click the FSR Update icon in the list of applications.
3. Your username is your employee number.
4. Your password by default is your date of birth. (Once you've logged in
once, you can change your password. Take note that this password is
independent of any other passwords you might have.)

If you are denied access to the database, please send an email to the field
management for help.

Thank you and welcome to the field organization!

Field Management

**************************End of Message*******************

When I click the button that runs this code, it gives me an error message
that says, "An expression you entered is the wrong data type for one of the
arguments".

How do I change the data type of the txtMsgBody text box to something like
Memo or something that will allow carriage returns and a whole bunch of
characters?

BruceM said:
You could do something like this with SendObject:

Docmd.SendObject acSendNoObject, , ,"(e-mail address removed)", , , "Subject","Go
here to open database"

That's all on one line in the code window, by the way.
I couldn't tell you about the template file part of the code, but I suspect
it has to do with using Access on the web. If all you need to do is send a
text message, something like the code above should do the trick. Substitute
control names for any item as needed. For instance, if the e-mail address is
in txtEmail on the form, the e-mail address in the code would be
Me![txtEmail]. If the message is standard for all recipients it could be
contained in a text box (hidden, if you like) on the form, or even in another
table. How you reference it in the code depends on the details of what you
need to do. Even if you could come up with at html e-mail I don't think you
would want to, as some recipients may use plain text.
If you start typing the code in the code window it will probably suggest
options as you go. When To is highlighted you would enter the information
for the To line of your e-mail message, etc. You need the empty commas as
space holders for things you are not including, but you don't need commas at
the end.

:

I've added a button to the form and created a macro to run with the onclick
event. In the macro I'm using the sendobject action. Down in the Action
Arguments pane there's a Template File field. In the help section on the
right it says, "Enter the full path of the file to use as a template for your
output. This argument only applies to HTML formats. Leave blank to use no
template. Press F1 for help on this action."

In help, all it says about this argument is, "The path and file name of a
file you want to use as a template for an .html file. The template file is a
file containing HTML tags."

Does this mean that I can only use the Template File action argument if I
only intend to use the SendObject action to create a "webpage" based off a
template? If that's the case, that's not at all what I want to do.

I just want to send an email to the person whom we've just created a new
record for that contains instructions on how to access the database. But I'd
rather these instructions be in the body of the message rather than as an
attachment.

I'm this has got to be possible in code, but I've got to be the worst
programmer on the face of this planet. :(

:

Not sure what you mean by the template field. Also, I don't know how you are
doing this, so it is hard to know what is going wrong wrong. Are you
attempting to embed something from the database into the body of an html
e-mail message, or are you sending an attachment, or something else? Are you
using SendObject? If not, see Help for details. It may do what you need.

:

I've got a form that collects a little information about employee's. What I
want the form to do is once it's been filled out and they click the "save and
close" button, I want it to automatically send an email to the address in the
email field. I've got this mostly working except for a couple things. I
want the message body to contain more that just 256 characters and for some
reason the template field doesn't seem to do anything. I created a template
in .html format and put the path in the appropriate field but none of it
appears in the email. Am I doing something wrong? thanks.
 
Dear Bruce,
How can one use SendObject with long email messages in access 2000?
My code works perfectly with access 2003, but creates an error running in 2000
Thanks


BruceM said:
Cool. I hadn't known about the Access 2000 difficulty with long e-mail
messages and SendObject. I have used chr(13) and chr(10) in code, which as I
understand is the same as vbCrLf, but never for an e-mail. My use of
SendObject so far has been to open an e-mail message, with maybe something in
the Subject line. Good work figuring that one out.

Jonathan Brown said:
Bruce, I figured it out!

I wasn't aware how to use vbCrLf or what it was even. It works perfectly
now. Check out the code I used:

***************beginning of code*******************
Dim objOutlook As New Outlook.Application
Dim objMail As MailItem

Set objOutlook = New Outlook.Application
Set objMail = objOutlook.CreateItem(olMailItem)

EmailAddr = Me.Email
CopyEmailAddr = ""
Subj = "Information about the FSR Update database."
Body = "Dear " & Me.FirstName & " " & Me.LastName & "," & vbCrLf & vbCrLf & _
"This email is intended to introduce you to the FSR Update database.
In this database you are given the opportunity to provide your contact and
emergency contact information. It also allows you to keep track of other
types of information, such as; passports, visas, vaccinations and mobility
training. You are urged to keep this information up to date. This database
provides a number of services to the field organization and is used quite
frequently by the field management." & vbCrLf & vbCrLf & _
"To access this application please follow the underlying steps:" &
vbCrLf & vbCrLf & _
"1. Login to Citrix. (If you are unfamiliar with Citrix, feel free
to ask your supervisor for help)" & vbCrLf & _
"2. Click the FSR Update icon in the list of applications." & vbCrLf
& _
"3. Your username is your life number." & vbCrLf & _
"4. Your password by default is your date of birth. (Once you've
logged in once, you can change your password. Take note that this password
is independent of any other passwords you might have.)" & vbCrLf & vbCrLf & _
"If you are denied access to the database, please send an email to
the field management for help." & vbCrLf & vbCrLf & _
"Thank you and welcome to the field organization!" & vbCrLf & vbCrLf
& _
"Field Management"
PathName = ""

With objMail
.To = EmailAddr
.cc = CopyEmailAddr
.Subject = Subj
.Body = Body
.NoAging = True
.Display
End With

**********************end of code*********************

I had to add the Microsoft Outlook object library to my references to use it
correctly.

Jonathan Brown said:
Okay Bruce, I think I'm really close but I still need you to hold my hand on
this one. This is what I've added:

DoCmd.SendObject acSendNoObject, , , Me.Email, , , "Information about the
FSR Update database", Me.txtMsgBody, True

On my form I've added a text box called txtMsgBody. I made it hidden and
added the following text to the Control Source property:

**********************Begginning of Message******************

Dear Sir or Madam,

This email is intended to introduce you to the FSR Update database. In this
database you are given the opportunity to provide your contact and emergency
contact information. It also allows you to keep track of other types of
information, such as; passports, visas, vaccinations and mobility training.
You are urged to keep this information up to date. This database provides a
number of services to the field organization and is used quite frequently by
the field management.

To access this application please follow the underlying steps:

1. Login to Citrix. (If you are unfamiliar with Citrix, feel free to ask
your supervisor for help)
2. Click the FSR Update icon in the list of applications.
3. Your username is your employee number.
4. Your password by default is your date of birth. (Once you've logged in
once, you can change your password. Take note that this password is
independent of any other passwords you might have.)

If you are denied access to the database, please send an email to the field
management for help.

Thank you and welcome to the field organization!

Field Management

**************************End of Message*******************

When I click the button that runs this code, it gives me an error message
that says, "An expression you entered is the wrong data type for one of the
arguments".

How do I change the data type of the txtMsgBody text box to something like
Memo or something that will allow carriage returns and a whole bunch of
characters?

:

You could do something like this with SendObject:

Docmd.SendObject acSendNoObject, , ,"(e-mail address removed)", , , "Subject","Go
here to open database"

That's all on one line in the code window, by the way.
I couldn't tell you about the template file part of the code, but I suspect
it has to do with using Access on the web. If all you need to do is send a
text message, something like the code above should do the trick. Substitute
control names for any item as needed. For instance, if the e-mail address is
in txtEmail on the form, the e-mail address in the code would be
Me![txtEmail]. If the message is standard for all recipients it could be
contained in a text box (hidden, if you like) on the form, or even in another
table. How you reference it in the code depends on the details of what you
need to do. Even if you could come up with at html e-mail I don't think you
would want to, as some recipients may use plain text.
If you start typing the code in the code window it will probably suggest
options as you go. When To is highlighted you would enter the information
for the To line of your e-mail message, etc. You need the empty commas as
space holders for things you are not including, but you don't need commas at
the end.

:

I've added a button to the form and created a macro to run with the onclick
event. In the macro I'm using the sendobject action. Down in the Action
Arguments pane there's a Template File field. In the help section on the
right it says, "Enter the full path of the file to use as a template for your
output. This argument only applies to HTML formats. Leave blank to use no
template. Press F1 for help on this action."

In help, all it says about this argument is, "The path and file name of a
file you want to use as a template for an .html file. The template file is a
file containing HTML tags."

Does this mean that I can only use the Template File action argument if I
only intend to use the SendObject action to create a "webpage" based off a
template? If that's the case, that's not at all what I want to do.

I just want to send an email to the person whom we've just created a new
record for that contains instructions on how to access the database. But I'd
rather these instructions be in the body of the message rather than as an
attachment.

I'm this has got to be possible in code, but I've got to be the worst
programmer on the face of this planet. :(

:

Not sure what you mean by the template field. Also, I don't know how you are
doing this, so it is hard to know what is going wrong wrong. Are you
attempting to embed something from the database into the body of an html
e-mail message, or are you sending an attachment, or something else? Are you
using SendObject? If not, see Help for details. It may do what you need.

:

I've got a form that collects a little information about employee's. What I
want the form to do is once it's been filled out and they click the "save and
close" button, I want it to automatically send an email to the address in the
email field. I've got this mostly working except for a couple things. I
want the message body to contain more that just 256 characters and for some
reason the template field doesn't seem to do anything. I created a template
in .html format and put the path in the appropriate field but none of it
appears in the email. Am I doing something wrong? thanks.
 
hello jonathan, this is rwest, wanted to know if you knew in outlook how to
access the close & save icon, its not bold black, its slightly light in
color, and it won't let me save or close,can you help me on that bro, please
advise,
 
Back
Top