Basic userform problem

becklog

New Member
Joined
Dec 26, 2016
Messages
38
Hi,


I have a userform with 4-5 items (depending on the selected option) to put in and a submit button. The first box requires the user to add a 6 letter-ticket and a list of options for the remaining 4. Is there a way to halt the operation if the following criteria is met:

- if the first option has less than 6 letters or empty.
- in the event that a user selects the option that requires 5 data and leave the 5th data empty
- if the user leave any textbox empty.

Thank you in advance
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hello becklog,

If your questions are about TextBoxes on the SUser Form:

Q - if the first option has less than 6 letters or empty.
A - Set the TextBox MaxLength property to 6. This limits the input to a maximum of 6 characters only.

Q
- in the event that a user selects the option that requires 5 data and leave the 5th data empty.
A - What are these Data? Where are they input to?

Q
- if the user leaves any textbox empty.
A - You can check each TextBox Value property and pop up a message that it needs to be filled in before continuing.

Rich (BB code):
Rich (BB code):
' // Enter this code into the General Declarations Section of the UserForm

Dim Closing As Boolean

Function IsTextMissing() As Boolean
    If ActiveControl.Object.Value = "" And Not Closing Then
        MsgBox "Please Enter Text into this Field.", vbExclamation
        IsTextMissing = True
    End If
End Function

' // Add this code to each TextBox Exit event
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Cancel = IsTextMissing
End Sub

' // Add this code to the UserForm QueryClose Event
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Closing = True
End Sub






 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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