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

Form_Open and error handling code

Status
Not open for further replies.

Custardptt

Technical User
Jan 12, 2005
31
GB
Hi All,
Sorry to trouble but I'm having the following problem.
I need to determine if an array is empty or not. Since there doesnt seem to be any official function for this I set an "On Error Goto ...." error handler then did a intVar = UBound(arrayname). If the array was empty it threw an error and the code jumped to the label, great.

Everything went wrong when I tried to use this approach in a 'Form_Open' event. The error is not handeled and I get a "subscript out of range error"

The code is below, Anyone got any suggestions

On Error GoTo SortImagesSection
PhotoTempFolderRowCount = UBound(PhotoTempFolderArray)
On Error GoTo 0

Many Thanks

Pete
 
Try this:

Code:
On Error GoTo Err_SortImagesSection
PhotoTempFolderRowCount = UBound(PhotoTempFolderArray)
'do stuff until error occurs

'If no error occurs, the next 2 lines
'are the last that will execute

Exit_SortImagesSection:
     Exit Sub

'If an error occurs, code will jump to here
'set the error to 0 and attempt the next line
Err_SortImagesSection:
    Err = 0
    Resume Next

End Sub

If that doesn't do it, try this:
Code:
On Error GoTo Err_SortImagesSection
PhotoTempFolderRowCount = UBound(PhotoTempFolderArray)
'do stuff until error occurs

'If no error occurs, the next 2 lines
'are the last that will execute

Exit_SortImagesSection:
     Exit Sub

'If an error occurs, code will jump to here
'set the error to 0 and attempt the next line
Err_SortImagesSection:
    Msgbox Err.Description
    Resume Exit_SortImagesSection

End Sub

Hope this helps...
Tom


Live once die twice; live twice die once.
 
Oops! Second description should be:
Code:
On Error GoTo Err_SortImagesSection
PhotoTempFolderRowCount = UBound(PhotoTempFolderArray)
'do stuff until error occurs

'If no error occurs, the next 2 lines
'are the last that will execute

Exit_SortImagesSection:
     Exit Sub

[!]'If an error occurs, code will jump to here
'pop up a message indicating what the error is
'then exit the sub routine[/!]
Err_SortImagesSection:
    Msgbox Err.Description
    Resume Exit_SortImagesSection

End Sub


[COLOR=green]Live once die twice; live twice die once.[/color]
 
How are ya Custardptt . . .

In what event ( or where!) . . . do you initialize the array?

Calvin.gif
See Ya! . . . . . .
 
Hi guys thenks for your help and sorry for getting back so late. My woes were multiplied by a failing PSU over the weekend.

It turns out the error was produced by my own stupid fault. I included the code in the 'On Open' event but the code relied on some additional values in text boxes. The were populated by the same form that called this one. Of course the values were populated after the 'on open' event so the code didnt see them and crashed.

I did continue to have problems elsewhere using this method of detecting an empty array. It does not work as intended if usedn in a loop. ( I think there are consequences of using the 'On Error' method I do not fully understand). Consequently I modified the function that produced the Array (returns a variant) to return 'Null' instead of an empty array. I was then able to use the IsArray() function.


Thanks once again for helping

Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top