Populate e-mail address button

lsearcey

Board Regular
Joined
Sep 8, 2003
Messages
139
I made a button using the Sendmail command so when I click it it brings up outlook e-mail. Is there a way to put the the e-mail address stored in the one of the fields in my database in the To line in Outlook express?

Thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
This has worked for me, where txtEmail is the field on the form containing the email address.

Private Sub cmdEmail_Click()
Dim EmlAdd As String
EmlAdd = Me.txtEmail
DoCmd.SendObject , , , EmlAdd
End Sub
 
Upvote 0
I put the information in the form containing the e-mail address in the "name" part under the "other" tab. And got the following message:

"The control name you entered doesn't follow Microsoft Access object-naming rules"
Any ideas on what I should to do to fix it. Thanks for your help
 
Upvote 0
The "name" part under the "other" tab is just the place where you can change the name of the control that is currently selected. In the above code I called the button cmdEmail, and the textbox txtEmail.
I assume you have a button on your form and a textbox that is bound to a field in your underlying table that has email addresses in it.
Open your form in design view. Click once on your button to select it and go to the Events tab of the properties window. Click in the field next to the OnClick event and choose "Event Procedure", then click the button that appears to the right of that to open the VBA window. Paste the code from my above message and change cmdEmail and txtEmail to whatever your button and textbox are named. Hope that helps.
 
Upvote 0
I added and it works but if I don't send the e-mail and close Outlook I get the following message is there a way to fix it? Thanks for all your help.

Run-time error '2501':
The SendObject action was canceled.
You used a method of the DoCmd object to carry out an action in Visual Basic, But then clicked Cancel in a dialog box.
For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that asks if you want to save the changes you made to the form.
 
Upvote 0
Hmm. I don't get that error. You could try to trap it, but I'm not sure where exactly to put the error handling code. Try replacing the above code with this:
Code:
Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click

Dim EmlAdd As String
EmlAdd = Me.txtEmail
DoCmd.SendObject , , , EmlAdd

Exit_cmdEmail_Click:
    Exit Sub

Err_cmdEmail_Click:
If Err.Number = 2501 Then
    Resume Next
Else
    MsgBox Err.Description
End If
    Resume Exit_cmdEmail_Click
End Sub

If that doesn't catch it, then maybe in the OnError event of your form you could put:

Code:
If Err.Number = 2501 Then
    Resume Next
Else
    MsgBox Err.Description
End If

Failing that, perhaps someone else here can help out with this.
 
Upvote 0

Forum statistics

Threads
1,221,668
Messages
6,161,163
Members
451,687
Latest member
KENNETH ROGERS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top