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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emailing Forms Another Question

Status
Not open for further replies.

merk

IS-IT--Management
Nov 30, 2001
32
US
I read an answer to a similar question in this forum, but I need to ask a similar question:

I have an access form that I would like to email. I would like to place a button on the form that would place the information from the fields on the form into an email message. I only want the information from that current record to be in the message (preferably without being an attachment).

I tried to use a macro to achieve this task, but the macro will only let me make the information be sent as an attachment. Additionally, the attachment contains all the information from that form, not just the single record.

I am not a programmer, so any help would be appreciated!
 
Well, while a programmer you may not be; a programmer to be you are.

Build your command button on the form and put this code with any alterations you may wish to make as the on click event of your button.

Dim rst As Recordset
Dim fld As Field
Dim strMessage As String, strEmail As String, strSubj As String

Set rst = me.recordsetclone
Rst.bookmark = me.bookmark

For Each fld In rst.Fields
strMessage = strMessage & fld.Name & ": " & fld.Value & vbCr
Next

strEmail = "someusernamehere"
strSubj = "your subject here”
DoCmd.SendObject acSendNoObject, , , strEmail, , , strSubj, strMessage,
False

Rst.close
Set rst = Nothing

You have now become a programmer in training.

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Thank you very much for the help and the encouragement. I am having one problem with the code. When press the button I get an error that says 'Member or data member not found'. The debugger then points me to this line:

DoCmd.SendObjectacSendNoObject , , , strEmail, , , strSubj, strMessage, False

Thanks for any further help!
 
You need a space between sendobject and acsendnoobject Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Now I get an error 3021: no current record. The debugger then points to this line:

rst.Bookmark = Me.Bookmark

Thanks for the patience and help with a newbie like me.
 
Since I'm not standing over you, I have to ask questions and make educated guesses.

First is there a record on your form. If it is a new record, for this to work you will have to save it. Just move backwards one record to force the update, then go back to the new record which will no longer be a new record.

if you still have problems, post back. Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Getting there...

Now I get an error 2295 which states that there is no email recipient. This problem is partly my fault because I would like to be prompted on address of the email recipient. Can this be done easily?

If not, I suppose that I can create separate buttons for each recipient (it would only be 2-3 people).

Thanks very much.
 
You will have to supply the recipient name yourself. Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Two more quick questions:

1. I get an error 91 on when sending with a specific email address:

Object variable or with block variable not set

2. I was also wondering if I could manipulate which fields get placed in the message.


Thanks!
 
Two more quick questions:

1. I get an error 91 on when sending with a specific email address:

Object variable or with block variable not set

Check the name Address of your recipient. It should be like jones@xyz.com. Quite often an invalid recipient name will cause this error.

2. I was also wondering if I could manipulate which fields get placed in the message.

The routine I sent you captuires all associated values shown on your form. You can use an array of the controls you want to send or even specify them one line at a time.


Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
What are the controls? If there are too many, please give me a place to look for them.


Thanks for the help!
 

Assuming you have 4 items, string1 thru string 4 which you want to send to your recipient. Get rid of this loop

For Each fld In rst.Fields
strMessage = strMessage & fld.Name & ": " & fld.Value & vbCr
Next


And replace it with
With rst
Strmessage = !string1 & vbcr & !string2 & vbcr & !string3 & vbcr & !string4
End with

Doing this will send those strings to the recipient.
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
I must be doing something wrong. Do I literally type in 'string'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top