Error Handler won't trigger if Runtime Error is 380 (Could not set RowSource property)

Sabotage

Board Regular
Joined
Sep 19, 2013
Messages
58
Hi Wizzards!
I have a problem not being able to trigger my error handler after the code is trying to set an "empty list" for combobox rowsource. In a nutshell my code is trying to set the rowsource for a combobox, depending on a value in another combobox's value. I have tried to put "On Error GoTo Err1" where Err1 is my Error Handler. Tried to put it before Select Case and inside Select Case but no luck what so ever. My Error Handler would just tell the user that the specified supplier does not have any store location set and exit the procedure. The user hence will know what is wrong...

Thank you in advance!

Code:
        Select Case cb_Supplier
            Case "Supplier ABC"
                On Error GoTo Err1
                cb_StoreName.RowSource = "SupLoc_ABC"   'error occurs
                On Error GoTo 0
            Case "Supplier XYZ"
                On Error GoTo Err1
                cb_StoreName.RowSource = "SupLoc_XYZ"   'error occurs
                On Error GoTo 0

        End Select
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
try

Code:
       On Error Resume Next 
       Select Case cb_Supplier
            Case "Supplier ABC"
                cb_StoreName.RowSource = "SupLoc_ABC"   'error occurs
                On Error GoTo Err1
            Case "Supplier XYZ"
                cb_StoreName.RowSource = "SupLoc_XYZ"   'error occurs
                On Error GoTo Err1
        End Select
 
Upvote 0
Are these comboboxes embedded on a
- worksheet ? OR UserForm ?

What is "SupLoc_ABC" ?
- is it a named range?
 
Upvote 0
What does your error handler look like? If it doesn't use Resume, your code will fail on the second error.
 
Upvote 0
In that case try this method to set the RowSource
Code:
cb_StoreName.RowSource = ThisWorkbook.Names("SupLoc_ABC").RefersTo
(have not checked if this works with dynamic named ranges - will test when back at PC later today)

But I am a little puzzled at where you are going with this code :confused:
- are you planning on listing all the possible suppliers inside Select Case?

You could use something like this if the named ranges are all SupLoc_ followed by the value found in cb_Supplier
Code:
Private Sub cb_Supplier_Change()
        Dim n As String
        n = "SupLoc_" & cb_Supplier.Value
        On Error Resume Next
            cb_StoreName.RowSource = ThisWorkbook.Names(n).RefersTo
                If Err.Number > 0 Then
                    MsgBox "named range " & n & "does not exist"
                    Exit Sub
                End If
End Sub
 
Last edited:
Upvote 0
What does your error handler look like? If it doesn't use Resume, your code will fail on the second error.


Hi Rory,
Thank you for trying to help. The error handler looks as the below code. I thought that when the error occurs it should just jump to the handler line and tell the user what the problem thereafter exit the sub. Where does it needs to Resume? The named range is currently empty, so returns an invalid 0 length list which cannot be assigned to the RowSource property.

Code:
Err2:
    'if there is no store for the specified supplier!
        MsgBox "This specified Supplier doesn't have any Store Location set!" & vbNewLine & vbNewLine & _
            "Please set up all Store names before trying to register a new load!", vbInformation, "Error..."
        Application.ScreenUpdating = True
        Exit Sub
 
Upvote 0
Yongle,
The SupLoc_**** is a dynamic list of locations under each supplier. On the UserForm when the the Supplier is being picked cb_Supplier then the next cbox is populating the list of corresponding locations. I have tried all your suggestions, no matter how I try to trigger my ErrorHandler or Resume Next. Just keep triggering the VBA error:

Run-time error '380':
Could not set the RowSource property. Invalid property value.
 
Upvote 0
In the VB Editor, under Tools - Options, on the General tab, which error handling option do you have checked?
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top