Error 424: Object Required - Option Buttons in If statements

TheDadliestDad

New Member
Joined
Feb 17, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello!

I want to say I'm missing something very small here, but I could be wrong, haha. Basic backstory here is that I am trying to build a Kanban system for our machine parts. I'm building a skeleton of the logic to get the proof of concept across to my team, but I'm running into a weird issue at my first ElseIf statement.

Here is what my GUI looks like that I've created:

1679338990609.png


Here is my VBA Code:
VBA Code:
Private Sub ExecuteButton_Click()
    
    Dim database As ListObject
    Dim FoundBin As Range
    Dim LookupBin As String
    
    Worksheets("Database").Activate
    
    Set database = ActiveSheet.ListObjects("Database")

    If optTakingPart.Value Then
    
        'do taking a part logic
        MsgBox "You are Taking a Part"
    
    ElseIf optAddingPart.Value Then
    
        'do adding a part logic
        MsgBox "You are Adding a Part"
    
    ElseIf optFindMyPart.Value Then
    
        'do finding a part logic
        MsgBox "You are Finding a Part"
    
    End If

    Worksheets("GUI").Activate
    TextBox1.Text = ""
End Sub

For this proof of concept I'm trying to just get a different message to display when each radio button is selected and the go button is clicked. As an example:

1679339182730.png

The above message box displays when I have the first radio button selected, but when I have either of the other two selected I get an error shown below...

1679339257010.png


If anyone can help I would greatly appreciate it. I'm not unfamiliar with vba in excel, but it's been a little while since I used it last.

Thank you!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Can I suggest doing a check of which options are checked before proceeding? Something like this:

VBA Code:
Dim lngSelections As Long

If optTakingPart Then lngSelections = lngSelections + 1
If optAddingPart Then lngSelections = lngSelections + 1
If optFindMyPart Then lngSelections = lngSelections + 1

If lngSelections < 1 Then

   MsgBox "You must select an action!", _
      vbCritical + vbOKOnly, "No, yo"
   Exit Sub
   
End If

If lngSelections > 1 Then

   MsgBox "You can only select ONE action to perform!", _
      vbCritical + vbOKOnly, "No, yo"
   Exit Sub
   
End If
 
Upvote 1
Hi Wookiee!

Thanks so much for your prompt reply. What you had suggested worked just fine, but it had set me on the right path to figuring out what was wrong with the first method. Your method initially wasn't working either for the second option of adding a part to the database, so I looked and found that the name was not exactly correct on my code. I had referenced the option button in my code as optAddingPart, but it should've been optAddingParts. I fixed that and it works beautifully. I'm sorry I didn't notice it sooner, but I'm glad your method help me find what was wrong!

Thanks so much!
 
Upvote 0
Solution
That's awesome! I'm glad I was able to help. 🤘
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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