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

Create macro button that emails form

Status
Not open for further replies.

jenwalton

Technical User
Oct 25, 2001
7
US
Hi,

I am trying to create a macro that, when pressed, will bring up an email from Outlook and has the Project ID number (a field from my form) automatically filled in and addressed to a specific employee (also a field on my form). Is this possible? I got as far as creating a button that brings up a blank email message, but it doesn't really do me any good... Any help? Thanks!
 
put this code behind a button to bring up email..you will have to create a form with some unbound fields..look at the code for the name of the fields...

Private Sub cmdSend_Click()

Dim stext As String
Dim ctext As String
Dim sAddedtext As String
If Len(txtMainAddresses) Then
stext = txtMainAddresses
End If
If Len(txtCC) Then
sAddedtext = sAddedtext & "&CC=" & txtCC
ctext = txtCC
End If
If Len(txtBCC) Then
sAddedtext = sAddedtext & "&BCC=" & txtBCC
End If
If Len(txtSubject) Then
sAddedtext = sAddedtext & "&Subject=" & txtSubject
End If
If Len(txtBody) Then
sAddedtext = sAddedtext & "&Body=" & txtBody
End If
If Len(txtAttachment) Then
sAddedtext = sAddedtext & "Attach=" & Chr$(34) & Me!txtAttachment & Chr$(34)
End If

stext = "mailto:" & stext
ctext = "cc:" & ctext

If Len(sAddedtext) <> 0 Then
Mid$(sAddedtext, 1, 1) = &quot;?&quot;
End If

stext = stext & sAddedtext


If Len(stext) Then
Call ShellExecute(Me.hwnd, &quot;open&quot;, stext, vbNullString, vbNullString, 0)
End If
DoCmd.Close , , acSaveNo

' txtMainAddresses = &quot;&quot;
'txtCC = &quot;&quot;
' txtBCC = &quot;&quot;
' txtSubject = &quot;&quot;
' txtBody = &quot;&quot;
' txtAttachment = &quot;&quot;

End Sub DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
sorry you'll need this to.. create a module and save it as
modShellExecute

Public Declare Function ShellExecute Lib &quot;shell32.dll&quot; _
Alias &quot;ShellExecuteA&quot; (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top