How do I point to several text boxes on a form MSAccess 2003 using VBA

I am using this code to send emails from MSAccess2003

I added tb for textbox for the Body so that I could insert text in the body from a form.
My question is:
1.  How do I add code for another text box for Subject
2.  How would I add code for dropdown for who the email is going to.  I am thinking I will have a drop down for people to select the email address to send to.

Thanks in advance.

leezacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
Please post your code.
0
leezacAuthor Commented:
Private Sub Command0_Click()
Dim olApp As Object
Dim objMail As Object
Dim tb As TextBox

Set tb = Forms!Form1!Text3


On Error Resume Next 'Keep going if there is an error


Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open


If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If

'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)

With objMail

'Set body format to HTML
.BodyFormat = olFormatHTML
.To = "email@abc.com"
.Subject = "Subject"
.HTMLBody = tb
.send

End With

MsgBox "Operation completed successfully"


End Sub
0
mbizupCommented:
You don't need to declare an object for your textboxes.  Check out the changes below:

Private Sub Command0_Click()
Dim olApp As Object
Dim objMail As Object


On Error Resume Next 'Keep going if there is an error


Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open


If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If

'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)

With objMail

'Set body format to HTML
.BodyFormat = olFormatHTML
.To = "email@abc.com"
.Subject = Forms!YourFormName.YourAddressBox
.HTMLBody = Forms!YourFormName.YourTextBoxName
.send

End With

MsgBox "Operation completed successfully"


End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.