Error In Assigning A Combobox Value To A Variable value

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
This I'm sure is a simple problem to resolve, but it's eluding me.

Code:
UserForm1.uf1cbx1_operatorini.Value = sgini

uf1cbx1_operatorini is a combobox with a series of 6 selectable values. If the value does not exist in the list, the user can select "other" from the list prompting them with an input box to enter a value (sgini).
When the code reaches the line above, it breaks with error "Could not set the Value property. Invalid property value."

Is anyone able to suggest what might be a cause of this error? I have been thinking it might have something to do with the fact that the value represented by variable sgini isn't in the rowsource of the combobox. If so, is there a way I can bypass this limitation?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Get rid of the RowSource property & load the combo like
Code:
Me.ComboBox1.List = Range("A2:A10").Value
 
Upvote 0
Hi Fluff, thanks for the suggestion.
In my userform initialization code I added:
Code:
Me.uf1cbx1_operatorini.List = ws_sheet2.Range("O34:O42").Value
and removed the rowsource property value.

Sadly, I continue to get the same error.
 
Upvote 0
Maybe the MatchRequire property is set to True and you're trying to assign it a value that doesn't exist in its list of items?
 
Upvote 0
How is that code being run?
 
Upvote 0
The MatchRequire property had been already set to False.
Fluff, not sure how to answer your question (not sure what you mean) but I've been stepping through (F8) each line from a set breakpoint after the combobox change event.
 
Upvote 0
Try changing the event from a change event to a click event.
Code:
Private Sub uf1cbx1_operatorini_Click()
 
Upvote 0
Oh no. I feel, contrary to my original post, that this really as simple a solution as I thought.
Changing the event type didn't work.

Now, I did not state that my erroneous code isn't in the Private Sub uf1cbx1_operatorini_Click() code. That may be an important and neglected part of the puzzle.
After the user selects "Other" from the uf1cbx1_operatorini combobox, the user is sent to a textbox on the same form to enter a value. In that textbox's exit code, the entry is error checked and manipulated to create the value for public variable 'sgini'. Once the value is constructed, it is sent out to populate the uf1cbx1_operatorini control with the line of code I'm having issue with.

Rich (BB code):
Private Sub uf1lbl1_name_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim sini, gini As String
    
    If Len(uf1lbl1_name) = 0 Then
        With uf1lbl1_name
            .Text = "Surname, Given"
            MsgBox "Improper name entry." & Chr(13) & "'Surname, Given'", , "ERROR"
            Cancel = True
            .ForeColor = RGB(220, 220, 220)
            .Font.Italic = True
            .SelStart = 0
            .SelLength = Len(uf1lbl1_name.Text)
        End With
    ElseIf InStr(uf1lbl1_name, ", ") < 1 Then
        With uf1lbl1_name
            .Text = "Surname, Given"
            MsgBox "Improper name entry." & Chr(13) & "'Surname, Given'", , "ERROR"
            Cancel = True
            .ForeColor = RGB(220, 220, 220)
            .Font.Italic = True
            .SelStart = 0
            .SelLength = Len(uf1lbl1_name.Text)
        End With
    ElseIf uf1lbl1_name.Text = "Surname, Given" Then
        With uf1lbl1_name
            .Text = "Surname, Given"
            MsgBox "Improper name entry." & Chr(13) & "Please use a real name.", , "ERROR"
            Cancel = True
            .ForeColor = RGB(220, 220, 220)
            .Font.Italic = True
            .SelStart = 0
            .SelLength = Len(uf1lbl1_name.Text)
        End With
    Else
        sini = Left(uf1lbl1_name, 1)
        gini = Mid(uf1lbl1_name, WorksheetFunction.Find(",", uf1lbl1_name) + 2, 1)
        sgini = gini & sini
        UserForm1.uf1cbx1_operatorini.Value = sgini
        
        With ws_salt
            If WorksheetFunction.CountIf(.Rows(2), sgini) = 0 Then 'new staff
                .Rows(2).Find("RP").Offset(, 1).EntireColumn.Insert 'insert column after RP
                rpc = .Rows(2).Find(what:="RP", LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False).Column
                .Range("B" & rpc) = sgini
                MsgBox sgini & " added to SAND OPS"
            End If
        End With
            
        With ws_sand
            If WorksheetFunction.CountIf(.Rows(2), sgini) = 0 Then 'new staff
                .Rows(2).Find("RP").Offset(, 1).EntireColumn.Insert 'insert column after RP
                rpc = .Rows(2).Find(what:="RP", LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False).Column
                .Range("B" & rpc) = sgini
                MsgBox sgini & " added to SAND OPS"
            End If
        End With
    End If
End Sub
 
Upvote 0
Unfortunately I'm not sure what else to suggest, as I cannot replicate the problem that you are having.
 
Upvote 0
Well, it wasn't without effort. Thanks Fluff!!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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