Tim Vavra
Tim Vavra

Reputation: 537

Checking for condition before continuing on a form

I am using Excel 2011 for Mac. I have a userform that contains 3 combo boxes. The data in the combo boxes is populated with information from the spreadsheet. The initialization populates the combo boxes. I have a button that initiates the processing of the data. In the first step of the process, I check that the user has not inadvertently pressed the button:

If (cmbStage.Text = "") Or cmbLowDt.Value = "" Or cmbHighDt.Value = "" Then
MsgBox "You are not ready to begin processing!", vbOKOnly
cmbStage.Text = ""
cmbLowDt.Value = ""
cmbHighDt.Value = ""

Else
End If

This basically checks if the users hasn't filled in anything. My problem is that if I add a GoTo command and have the check start again, since I called the function originally from the button click, I just loop through the message again and again.

What I want to do is check for the condition, if it exists, have the user start over as if they had not pushed the button. This is an essential part of the process as this comes after some lengthy processing to get to this point.

If I cannot do that I would just like to put a full screen message that says: " You are a complete idiot and should not be allowed anywhere near a computer for the balance of your natural life" ,vbOkayOnly

Upvotes: 0

Views: 118

Answers (1)

ebrts
ebrts

Reputation: 381

Since your button triggers a new process, why not just let that if statement be a gateway to the the rest of your code?

Sub buttonPress()
If (cmbStage.Text = "") Or cmbLowDt.Value = "" Or cmbHighDt.Value = "" Then
    MsgBox "You are not ready to begin processing!", vbOKOnly
    cmbStage.Text = ""
    cmbLowDt.Value = ""
    cmbHighDt.Value = ""
    End
Else
'Continue with your task
End If
End Sub

Or if you can't end ....

Sub buttonPress()
If (cmbStage.Text = "") Or cmbLowDt.Value = "" Or cmbHighDt.Value = "" Then
    MsgBox "You are not ready to begin processing!", vbOKOnly
    Set yourForm = aNewInstanceOfTheFOrm
    cmbStage.Text = ""
    cmbLowDt.Value = ""
    cmbHighDt.Value = ""
Else
'Continue with your task
End If
End Sub

Upvotes: 1

Related Questions