1

I've created a userform that will require an option button to be selected (thus emailing the intended recipient), otherwise it will display a msgbox.

I'm having a problem with the If And Then Else statements. I need the code to continue if one of the option buttons is selected, only display the msgbox if there are no option buttons selected.

I'm sure this is a newbie error. Any help would be greatly appreciated.

Private Sub cmdSend_Click()

If optbeasley.Value = False _
And optmaney.Value = False _
And optmessana.Value = False _
And opttimmerman.Value = False _
And opttrotter.Value = False _
Then MsgBox "Please Select a Contact"
Else:

Next i
Call Important_relocate_reformat

    If Me.optbeasley.Value = True Then
    Call Module4.Email_beasley
    Unload Me
    End If
        If Me.optmaney.Value = True Then
        Call Module4.Email_maney
        Unload Me
        End If
            If Me.optmessana.Value = True Then
            Call Module4.Email_messana
            Unload Me
            End If
                If Me.opttimmerman.Value = True Then
                Call Module4.Email_timmerman
                Unload Me
                End If
                    If Me.opttrotter.Value = True Then
                    Call Module4.Email_trotter
                    Unload Me
                    End If
                        If Me.chkMattBeasley.Value = True Then
                        Call Email_beasley
                        End If
If Me.chkRickLeshane.Value = True Then
Call Email_Important_Leshane
End If
        If Me.chkTimRuppert.Value = True Then
        Call Email_Important_Ruppert
        End If



End Sub
Private Sub optbeasley_Click()
If optbeasley.Value = True Then
        chkMattBeasley.Enabled = False
    Else
        chkMattBeasley.Enabled = True
    End If
End Sub

Private Sub optmaney_Click()
Call optbeasley_Click
End Sub
Private Sub opttimmerman_Click()
Call optbeasley_Click
End Sub
Private Sub opttrotter_Click()
Call optbeasley_Click
End Sub
Private Sub optmessana_Click()
Call optbeasley_Click
End Sub

I've edited to show the usage of your code:

Private Sub cmdSend_Click()

If optbeasley = 0 And optmaney = 0 And optmessana = 0 And opttimmerman = 0 And opttrotter = 0 Then
MsgBox "Please Select a Contact"
Else: Call cmdSend_Click2
End If

End Sub
  • Are you missing an extra End If at the end of your sub cmdSend_Click? – freekvd Feb 4 '15 at 8:24
  • I tried adding <code>End If</code> but it throws back an error IF End If without IF block I think – Joe Feb 4 '15 at 13:36
0

It's the formatting, apparently. This works -

Sub example()
Dim optbeasley As Range
Dim optmaney As Range
Dim optmessana As Range
Dim opttimmerman As Range
Dim optrotter As Range

Set optbeasley = Range("A1")
Set optmaney = Range("A2")
Set optmessana = Range("A3")
Set opttimmerman = Range("A4")
Set optrotter = Range("A5")

If optbeasley = False _
And optmaney = False _
And optmessana = False _
And opttimmerman = False _
And opttrotter = False Then
MsgBox "Please Select a Contact"
Else: MsgBox ("hi")
End If
End Sub
  • I need to check if no option buttons are selected. If one is selected, then I need to run the rest of the code. If the code detects that none of the option buttons are true, then the message box will appear and re-run the macro to check again. But if I run <code>ElseIf</code> won't it show the message box each time because one of the option buttons will not be selected, since only one can be selected at a time. – Joe Feb 4 '15 at 13:30
  • @Joe updated again – Raystafarian Feb 4 '15 at 14:01
  • This works fantastically! I appreciate your help. Since the Option Buttons (radio buttons) are not defined by cells on a spreadsheed (userform) I adapted to recognize them as option buttons. Thank you all for your time and help! – Joe Feb 4 '15 at 14:06
  • @Joe excellent, sorry I got pretty confused on the troubleshooting, hence all the edits. Glad it worked out finally – Raystafarian Feb 4 '15 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.