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

E mail attachments in Access 1

Status
Not open for further replies.

ANDYM

Programmer
Jul 6, 2000
15
0
0
GB
Does anyone have a solution which will allow a non Access Object, say a Word Document, to be e-mailed from within an Access/VB application.
 
This will send To, CC and BC as well as Subject, Message, and Attachment<br>You need 6 text boxes or variables which match the following:<br>txtMainAddresses<br>txtCC<br>txtBCC<br>txtSubject<br>txtBody<br>txtAttachment<br><br>Put this in your Module<br>------------------------------<br>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<br>------------------------------<br>put this in a command button<br>------------------------------<br>Private Sub Command0_Click()<br>On Error GoTo Err_Command0_Click<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim stext As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim sAddedtext As String<br>&nbsp;&nbsp;&nbsp;&nbsp;If Len(txtMainAddresses) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stext = txtMainAddresses<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;If Len(txtCC) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sAddedtext = sAddedtext & &quot;&CC=&quot; & txtCC<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;If Len(txtBCC) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sAddedtext = sAddedtext & &quot;&BCC=&quot; & txtBCC<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;If Len(txtSubject) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sAddedtext = sAddedtext & &quot;&Subject=&quot; & txtSubject<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;If Len(txtBody) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sAddedtext = sAddedtext & &quot;&Body=&quot; & txtBody<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;If Len(txtAttachment) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sAddedtext = sAddedtext & &quot;Attach=&quot; & Chr$(34) & Me!txtAttachment & Chr$(34)<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;stext = &quot;mailto:&quot; & stext<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;If Len(sAddedtext) &lt;&gt; 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mid$(sAddedtext, 1, 1) = &quot;?&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;stext = stext & sAddedtext<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;' launch default e-mail program<br>&nbsp;&nbsp;&nbsp;&nbsp;If Len(stext) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call ShellExecute(Me.hwnd, &quot;open&quot;, stext, vbNullString, vbNullString, SW_SHOWNORMAL)<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br><br>Exit_Command0_Click:<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br><br>Err_Command0_Click:<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox Err.Description<br>&nbsp;&nbsp;&nbsp;&nbsp;Resume Exit_Command0_Click<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br><br>------------------------------<br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
DougP<br><br>Thanks for this!<br>I can't find any info on the ShellExecute command. I can't get this to work as it is asking me to define the &quot;SW_SHOWNORMAL&quot;<br><br>Can you please explain the difference between shell and shellexecute?<br><br>Also what does SW_SHOWNORMAL and how can I define it?<br><br>Thanks.<br>Davo
 
Shell Execute a is function in the Shell32.dll<br>Look in your Windows\system folder for that file &quot;Shell32.dll&quot;. The difference is its an API call which can be called by any program like VB or C++<br>Shell is a function in VB and Access that is a stripped down version of ShellExecute.<br><br>If Shell32.dll is not there, then are you running Windows '95 not OSR-2?<br>I suspect that the reason SW_SHOWNORMAL is not available is because of a very early version of Windows too.<br>I am using Windows 2000 Professional. I know this also works in NT 4.0<br>I substituted a 1 for SW_SHOWNORMAL and it worked. <br>I just re-tested it right now to make sure it works and it does.<br>Now did you put the following in a module?<br><br>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<br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
DougP<br><br>Thanks. <br>Its works (ie calls the functions inside the shell.dll) my only problem now is that I have no Microsoft email software (lotus Notes v4.6 on NT4 with Access97). <br><br>lotus Notes v4.6 is MAPI compatiable.<br><br>My problem now is an error mesage <br>(title)Problem with short cut<br>(body)Cannot send mail. No program is setup to send mail using internet shortcuts.<br><br>Any suggestions?<br>Thanks<br>Davo<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top