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!

help with error handler

Status
Not open for further replies.

49er

Programmer
Aug 24, 2000
38
0
0
US
The following code is a sub that I have written. This procedure is called repeatedly. However, rsSelected is sometimes a valid array and sometimes it is not. What I want to happen is when I receive the 'subscript out of range' error then you just exit the sub without running the DrawSpatialRecordset function. What is wrong with the way I have my error handler set up? Thanks.

Public Sub DrawSelectedFeatures(ByVal hDC As StdOle.OLE_HANDLE)
On Error GoTo booboohandler
Dim i As Integer

For i = 1 To UBound(rsSelected)
DrawSpatialRecordset rsSelected(i), moPurple, moSolidFill
Next

booboohandler:
Exit Sub

End Sub
 
If you're getting a "subscript out of range" error with this, there's only a few things that it's likely to be:

1. The rsSelected array has a lower bound greater than 1. If this is the case, try "For i = LBound(rsSelected) To UBound(rsSelected)"

2. The rsSelected array was initialized with no argument (IE: "Dim rsSelected() As String"), and this routine is running before it gets "populated".

If this doesn't do it, please post more information about the rsSelected array.
 
I do this. run the program and let it stop on the error. then look at the Error Number in the upper Left of the message box its usually 2345 or something like
2345 "Syntax, Invalid handle Blah Blah Blah...

Then note the number.

Now in your "booboohandler" put this

------------------------------------------
Function MyThingy ….

‘ Put this right under the function name
On Error GoTo Booboohandler

'leave all your code in here

'put these lines at the end of your un-handled code
Exit_MyThingy:
Exit Function

Booboohandler:
Select Case Err.Number
Case 2345
' Syntax, Invalid handle Blah Blah Blah...

Case Else
MsgBox "Error # " & Err.Number & " " &Err.Description, vbInformation, "In sub MyThingy "
Resume Exit_MyThingy
End Select
-------------------------------------------------
End Function
DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top