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

Error message appears when no error occurs 1

Status
Not open for further replies.

Mantle51

Programmer
Aug 17, 2006
97
US
Hello,
The following code for a UserForm command button causes an error message(number 0)-which really resets the error check, even when the intended action performs flawlessly. I tooks steps to override in the err_OpenFile: section. I cannot determine what the cause is. Perhaps a better Open method?
Thanks........Mick

Private Sub cmdOpenFile_Click()
On Error GoTo err_OpenFile
Dim strFilePath As String
strFilePath = txtXLS.Value
Application.Workbooks.Open (strFilePath)
Unload Me
err_OpenFile:
If Err.Number = 0 Then
Exit Sub
Else: MsgBox Err.Description & " Error #" & Err.Number
End If
Exit Sub
End Sub
 
What about this ?
Private Sub cmdOpenFile_Click()
Dim strFilePath As String
On Error GoTo err_OpenFile
strFilePath = txtXLS.Value
Application.Workbooks.Open (strFilePath)
exit_OpenFile:
Unload Me
Exit Sub
err_OpenFile:
MsgBox Err.Description & " Error #" & Err.Number
Resume exit_OpenFile
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Still there. What's the difference between 'Exit Sub' and 'Exit_cmdOpenFile:' -Aren't they one and the same?
 
What is your actual code ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Right now it's the following(where txtXLS is a textbox that is populated with path to file)

Private Sub cmdOpenFile_Click()
On Error GoTo Err_cmdOpenFile
Dim strFilePath As String
strFilePath = txtXLS.Value
Application.Workbooks.Open (strFilePath)
Exit Sub
Unload Me
Err_cmdOpenFile:
If Err.Number = 0 Then
Exit Sub
Else: MsgBox Err.Description & " Error #" & Err.Number
End If
Exit Sub
End Sub
 
Seems uoy completly ignored my suggestion ...
 
I've tried it many different ways, even commented the Unload Me and still propogates the error message.

Thanks anyway......
 
And this ?
Private Sub cmdOpenFile_Click()
Dim strFilePath As String
On Error GoTo err_OpenFile
strFilePath = txtXLS.Value
Application.Workbooks.Open strFilePath
Unload Me
exit_OpenFile:
Exit Sub
err_OpenFile:
MsgBox Err.Description & " Error #" & Err.Number
Resume exit_OpenFile
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Sorry, it's been a long day, It DOES work PHV, so the exit_open file: was the trick?

Thanks again
 
The real trick, I think, is the Resume instruction.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
So if you specify

on error goto err_OpenFile
then exit_OpenFile is recognized as a component of err_OpenFile, even though it hasn't been referenced while the name of the macro is cmdOpenFile_Click?
 
No.
In your code place the cursor inside the Resume keyword and press the F1 key.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top