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

Email from Form hardcode mail address

Status
Not open for further replies.

kdschool

Technical User
Dec 17, 2013
6
0
0
US
i am using the code from a prior thread and I am running into a problem with the .To = email part of the code. It gives me an error message that says there must be at least one email address in the To field. I don't want to pull this from a field I would like to just hard code an email ID into that field since all the forms submitted should go to that one email address. I have not used VB and am not a programmer. If you could tell me how to handle this I would greatly appreciate it.

 
Did you try:[tt]

...
.To = "kdschool@some.place.com"
...[/tt]


Have fun.

---- Andy
 
Yes that worked and it's sending the email and it is updating the table but it's not sending the form data in the email.

Here is my code.

Private Sub AddRecordButton_Click()

Dim firstname, lastname As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

'**gathers information from your form. this sets the string variable to your fields
firstname = Me!firstname
lastname = Me!lastname

'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'***creates and sends email
With objEmail
.To = "jiwilson@xxx.com"
.Subject = "New Record"
.Body = "this is an new record"
.Send
End With

'**closes outlook
Set objEmail = Nothing
'** objOutlook.Quit
Exit Sub
End Sub

 
it's not sending the form data in the email."
What data would you like to send?

Right now you just have:[tt]
.Body = "this is an new record"[/tt]
and that's what you will have in the e-mail's Body.

BTW - Dim firstname, lastname As String
Only lastname is String, firstname is Variant


Have fun.

---- Andy
 
I wanted to send the firstname and lastname fields. I am trying to figure this at a very elementary level before I try to use it with a real project.
 
i see now. I put the field in the body statement and it show up. How can I add more than one field my syntax is wrong. OMG thank you so much!
 
Let's say you have on your Form a text box named txtFirstName and another one named txtLastName

Try:
[tt]
.Body = "Hello " & txtFirstName & vbNewLine
.Body = .Body & "Dear " & txtFirstName & " " & txtLastName
[/tt]

So if your txtFirstName has "Bob" and txtLastName has "Brown",
your e-mail should say:
[tt]
Hello Bob
Dear Bob Brown
[/tt]

If you can show me what you have and what you want to have, I may be able to help you. Just indicate which 'pieces' are the Form fields.

Have fun.

---- Andy
 
Yes that syntax works great. I see I need to learn some VB enough to get through this. Your help is greatly appreciated. I did not want to go this route unless I was sure I could send the form data through email upon entry since that was a requirement.

Thank you again.
 
I'm glad I could help you.

Welcome to Tek-Tips :)

Coma back if you have any questions....

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top