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

Can anyone tell me whats wrong with the following code: error handler

Status
Not open for further replies.

thetambarineman

Technical User
Feb 29, 2000
63
GB
This error handler was kindly generated by Dougp. Unfortunately for some reason some of it will just not function:<br>
<br>
I can't get the e-mail address to be separate from the subject and the body. I must be overlooking something, does anyone know what?:private Sub Command1_Click()<br>
On Error GoTo Err_Command1_Click<br>
<br>
' Raise the exception<br>
s = 3 / 0<br>
<br>
Exit_Command1_Click: '&lt;&lt;&lt; Put all this code at the bottom right above the END SUB<br>
Exit Sub<br>
<br>
Err_Command1_Click:<br>
Select Case Err.Number<br>
Case 3021<br>
' No current record<br>
<br>
Case Else<br>
MsgBox &quot;Error # &quot; & Err.Number & &quot; &quot; & Err.Description, vbInformation, &quot;In sub Command1_Click&quot;<br>
<br>
End Select<br>
<br>
Dim stext As String<br>
Dim sAddedtext As String<br>
<br>
stext = &quot;mailto:&quot; & &quot;douglasp&quot;<br>
<br>
sAddedtext = sAddedtext & &quot;&Subject=&quot; & &quot;Error From VB Program &quot; & Err.Number & &quot; &quot; & Err.Description<br>
sAddedtext = sAddedtext & &quot;&Body=&quot; & &quot;Put your Body Text here if needed&quot;<br>
<br>
'Add an attachment if needed<br>
'If Len(txtAttachment) Then<br>
'sAddedtext = sAddedtext & &quot;Attach=&quot; & Chr$(34) & Me!txtAttachment & Chr$(34)<br>
'End If<br>
<br>
stext = stext & sAddedtext<br>
<br>
' launch default e-mail program<br>
If Len(stext) Then<br>
Call ShellExecute(Me.hwnd, &quot;open&quot;, stext, vbNullString, vbNullString, SW_SHOWNORMAL)<br>
End If<br>
<br>
Resume Exit_Command1_Click<br>
<br>
<br>
Code generated by DougP<br>
<br>
Thanks in advance:<br>
Paul McLornan<br>
<br>

 
Not sure...<br>
Put a stop (F9) on this line<br>
stext = &quot;mailto:&quot; & &quot;douglasp&quot;<br>
and then press F8 to step through it.<br>
check the value of the variables<br>
using ?sAddedtext to see whats in it.<br>
each portion of the String needs a ? &quot;Question mark&quot; in between them.<br>
So if you are getting something strung together then there is a missing Question mark somewhere<br>
So if you say its in the e-mail address then there is no question mark between that and &quot;&Subject=&quot; <br>
Are the other items looking OK like &quot;body&quot;<br>
<br>
Is this your code or just my code from the post.<br>
Paste your exact code here and let me see it.<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
u r exact code:<br>
thanks again for your help!!<br>
<br>
<br>
<br>
Well I have 90% of it here:<br>
But it prompts for you to hit send.<br>
-----------------------<br>
Insert this Declare in your module<br>
<br>
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (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>
----------------------------------------<br>
Private Sub Command1_Click()<br>
On Error GoTo Err_Command1_Click<br>
<br>
' Raise the exception<br>
s = 3 / 0<br>
<br>
Exit_Command1_Click: '&lt;&lt;&lt; Put all this code at the bottom right above the END SUB<br>
Exit Sub<br>
<br>
Err_Command1_Click:<br>
Select Case Err.Number<br>
Case 3021<br>
' No current record<br>
<br>
Case Else<br>
MsgBox "Error # " & Err.Number & " " & Err.Description, vbInformation, "In sub Command1_Click"<br>
<br>
End Select<br>
<br>
Dim stext As String<br>
Dim sAddedtext As String<br>
<br>
stext = "mailto:" & "douglasp"<br>
<br>
sAddedtext = sAddedtext & "&Subject=" & "Error From VB Program " & Err.Number & " " & Err.Description<br>
sAddedtext = sAddedtext & "&Body=" & "Put your Body Text here if needed"<br>
<br>
'Add an attachment if needed<br>
'If Len(txtAttachment) Then<br>
'sAddedtext = sAddedtext & "Attach=" & Chr$(34) & Me!txtAttachment & Chr$(34)<br>
'End If<br>
<br>
stext = stext & sAddedtext<br>
<br>
' launch default e-mail program<br>
If Len(stext) Then<br>
Call ShellExecute(Me.hwnd, "open", stext, vbNullString, vbNullString, SW_SHOWNORMAL)<br>
End If<br>
<br>
Resume Exit_Command1_Click<br>
<br>
End Sub<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top