run-time error '450: wrong number of arguments or invalid property assignment

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
630
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
On my userform I have a frame and within that frame I have six option buttons, four labels, one datepicker, one textbox, three combo boxes, and two command buttons.
I am getting the above error when I run my For Loop and this error only occurs when the ctrl is Frame1.
VBA Code:
Private Sub CommandButton1_Click()
    'declares variables
    Dim ws As Worksheets
    Dim sDate As String
    Dim lastDateEntered As Range
    Dim ctrl As Control
    
    'Loop through all the controls on the userform
    For Each ctrl In UserForm1.Controls
        Select Case ctrl
            Case Is = "Please select batch under review"
                MsgBox "CB2"
            Case Is = "Please enter the lot number"
                MsgBox "TB1"
            Case Is = "Please select employee from the list"
                MsgBox "CB1"
            Case Is = "Please select error from the list."
                MsgBox "CB3"
        End Select
    Next ctrl
    
    sDate = Format(Date, "mmmm")
    Debug.Print sDate
    
    Worksheets(sDate).Select
    
    Debug.Print ActiveSheet.Name
    
    UserForm1.Hide
    batch = Me.ComboBox2.Value
    MachOp = Me.ComboBox1.Value
    machOpIni = Me.Label1
    BRError = Me.ComboBox3.Value
    Call foundBlank
    Unload Me
    
End Sub
Thank you
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
That is because you're trying to match a control to a string, you need to match the control name or caption for it to work.
Select Case ctrl.Name
 
Upvote 0
That's what I am needing it to do. So when the loop gets to a control, it needs to check the value, then display a message box if the value equals the text shown. How can I achieve this, is this possible? Thank you.
 
Upvote 0
As already suggested, try changing the select case line to Select Case ctrl.Name

You will need one of .Name, .Caption or .Value (most likely .Caption).
 
Upvote 0
You need something like this:

VBA Code:
  'Loop through all the controls on the userform
  For Each ctrl In Me.Controls
    If TypeName(ctrl) = "TextBox" Or TypeName(ctrl) = "ComboBox" Then
      Select Case ctrl.Value
        Case "Please select batch under review"
          MsgBox "CB2"
        Case "Please enter the lot number"
          MsgBox "TB"
          'or
          MsgBox ctrl.Name
        Case "Please select employee from the list"
          MsgBox "CB1"
        Case "Please select error from the list."
          MsgBox "CB3"
      End Select
    End If
  Next ctrl

Or maybe like this:

Code:
  'Loop through all the controls on the userform
  For Each ctrl In Me.Controls
    If TypeName(ctrl) = "TextBox" Or TypeName(ctrl) = "ComboBox" Then
      Select Case ctrl.Value
        Case "Please select batch under review", "Please enter the lot number", _
             "Please select employee from the list", "Please select error from the list."
          MsgBox ctrl.Name
      End Select
    End If
  Next ctrl

Or:

Code:
  'Loop through all the controls on the userform
  For Each ctrl In Me.Controls
    If TypeName(ctrl) = "TextBox" Or TypeName(ctrl) = "ComboBox" Then
      If Left(ctrl.Value, 6) = "Please" Then MsgBox ctrl.Name
    End If
  Next ctrl
 
Upvote 0

Forum statistics

Threads
1,226,412
Messages
6,190,900
Members
453,625
Latest member
SW82SW

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