Share via

VBA userform-required input

Anonymous
2013-08-14T13:01:10+00:00

i have a userform developed in vba. the 1st selection is 'cboNUM' which prompts the user to select a number from a list.

it is vital that this field is filled in. is there any  coding that forces a user to make this selection before doing anything else on the form.

thanks

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2013-08-14T13:17:58+00:00

Hi,

I assume the CboNum is a ComboBox. Right click the combobox 'View Code' and paste this code in.

You should edit the message to whatever is appropriate.

Private Sub CboNum_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If CboNum.Value = "" Then

    MsgBox "You must select a number in the combobox"

    Cancel = True

End If

End Sub

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2013-08-14T13:27:11+00:00

    thanks

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-08-14T13:26:26+00:00

    Thanks Mike-perfect as always

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-08-14T13:18:47+00:00

    Hi

    You can change the Enabled property of each other control to False

    Only a click in the list box will then ennable the other controls

    eg

    Private Sub ListBox1_Click()

    Dim cntl As CommandButton

     For Each cntl In Me

       cntl.Enabled = True

     Next

    End Sub

    or one by one

    me.CommandButton1.Enabled=True

    Regards

    JY

    Was this answer helpful?

    0 comments No comments