×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
This error handler was kindly generated by Dougp. Unfortunately for some reason some of it will just not function:

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()
On Error GoTo Err_Command1_Click

' Raise the exception
s = 3 / 0

Exit_Command1_Click: '<<< Put all this code at the bottom right above the END SUB
Exit Sub

Err_Command1_Click:
Select Case Err.Number
Case 3021
' No current record

Case Else
MsgBox "Error # " & Err.Number & " " & Err.Description, vbInformation, "In sub Command1_Click"

End Select

Dim stext As String
Dim sAddedtext As String

stext = "mailto:" & "douglasp"

sAddedtext = sAddedtext & "&Subject=" & "Error From VB Program " & Err.Number & " " & Err.Description
sAddedtext = sAddedtext & "&Body=" & "Put your Body Text here if needed"

'Add an attachment if needed
'If Len(txtAttachment) Then
'sAddedtext = sAddedtext & "Attach=" & Chr$(34) & Me!txtAttachment & Chr$(34)
'End If

stext = stext & sAddedtext

' launch default e-mail program
If Len(stext) Then
Call ShellExecute(Me.hwnd, "open", stext, vbNullString, vbNullString, SW_SHOWNORMAL)
End If

Resume Exit_Command1_Click


Code generated by DougP

Thanks in advance:
Paul McLornan

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

Not sure...
Put a stop (F9) on this line
stext = "mailto:" & "douglasp"
and then press F8 to step through it.
check the value of the variables
using ?sAddedtext to see whats in it.
each portion of the String needs a ? "Question mark" in between them.
So if you are getting something strung together then there is a missing Question mark somewhere
So if you say its in the e-mail address then there is no question mark between that and "&Subject="
Are the other items looking OK like "body"

Is this your code or just my code from the post.
Paste your exact code here and let me see it.

DougP
dposton@universal1.com

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

(OP)
u r exact code:
thanks again for your help!!



Well I have 90% of it here:
But it prompts for you to hit send.
-----------------------
Insert this Declare in your module

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

----------------------------------------
Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

' Raise the exception
s = 3 / 0

Exit_Command1_Click: '<<< Put all this code at the bottom right above the END SUB
Exit Sub

Err_Command1_Click:
Select Case Err.Number
Case 3021
' No current record

Case Else
MsgBox "Error # " & Err.Number & " " & Err.Description, vbInformation, "In sub Command1_Click"

End Select

Dim stext As String
Dim sAddedtext As String

stext = "mailto:" & "douglasp"

sAddedtext = sAddedtext & "&Subject=" & "Error From VB Program " & Err.Number & " " & Err.Description
sAddedtext = sAddedtext & "&Body=" & "Put your Body Text here if needed"

'Add an attachment if needed
'If Len(txtAttachment) Then
'sAddedtext = sAddedtext & "Attach=" & Chr$(34) & Me!txtAttachment & Chr$(34)
'End If

stext = stext & sAddedtext

' launch default e-mail program
If Len(stext) Then
Call ShellExecute(Me.hwnd, "open", stext, vbNullString, vbNullString, SW_SHOWNORMAL)
End If

Resume Exit_Command1_Click

End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close