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

Email with Fields From Record 1

Status
Not open for further replies.

jbento

Technical User
Jul 20, 2001
573
US
All,
I have the following code that works fine for some other function, but I would also like to have certain fields from a current record appear in the email. Do anyone know the code that could be tacked on to the below code? The email I have is at the bottom of the code.

Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
Dim db As DAO.Database, rst As DAO.Recordset
'Copy Record and Save Record to new table
Set db = CurrentDb
Set rst = db.OpenRecordset("MyTableName")
rst.AddNew

rst!field1 = Me!field1
rst!field2 = Me!field2
rst!field3 = Me!field3
rst.Update
rst.Close
db.Close

'send e-mail
DoCmd.SendObject acSendNoObject, "", acFormatTXT, "MyEmailAddress",,,"Subject Here", "message", True

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click

End Sub

I hope someone can help with the ending code. Thanks bunches!!!
 
Assuming the data you want comes from the form....Just plug in the variables as you would into the recordset. Or, you can use the variables from the recordset.


DoCmd.SendObject acSendNoObject, "", acFormatTXT, Me!txtSomething,Me!txtSomethingElse, Etc

Alternate

DoCmd.SendObject acSendNoObject, "", acFormatTXT, rst.fields(0),rst.Fields(1), Etc
 
Databaseguy,
I will try those tomorrow at work. Thanks again. I was on the right track:).

Jerome
 
Databaseguy,
Something is not right with the code. Below is the code I have in the sent function:

DoCmd.SendObject acSendNoObject, "",acFormatTXT, "EmailAddressHere",,,"SubjectLineTextHere", "BodyTextHere, Me!Field1,Me!Field2,Me!Field3",True

When the email opens, it brings over just the text "Me!Field1,Me!Field2,Me!Field3", it doesn't bring over the actual data that is associated with that field. What do you think is wrong with the code? Please help.

Jerome
 
Try this instead:

DoCmd.SendObject acSendNoObject, "",acFormatTXT, "EmailAddressHere",,,"SubjectLineTextHere", "BodyTextHere, " & Me!Field1 & ", " & Me!Field2 & ", " & Me!Field3, True

HTH Joe Miller
joe.miller@flotech.net
 
Joe is right.

"BodyTextHere, Me!Field1,Me!Field2,Me!Field3",True

Should be

"BodyTextHere", Me!Field1,Me!Field2,Me!Field3,True
 
DBGuy,

You're suggestion is wrong as well if he is doing what I think he's doing. He's trying to put the values of three fields in his body separated by commas. Your way would make his Field1 thru 3 act as arguments to the function because they are not enclosed by quotes and concatenated with the &.
Joe Miller
joe.miller@flotech.net
 
Joe,
I tried the code and it WORKED!!!! I even added vbNewLine to break up the fields:).

I would just like to say I thank you and I also thank Databaseguy, for giving me this assistance. With this knowledge I'm getting from this site, I have been able to help others. I have also sent a lot of people to this site. Thanks again for you both giving me the assistance I need.

Jerome
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top