Userform Textbox

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi all

3 questions relating to my userform textbox...

1) the 'string' entered into Textbox1 MUST be 6 characters long. So if less or more are entered a 'warning' - "please enter a six character ref" is displayed.

2) as part of these 6 characters entered I want any letters to be changed automatically to CAPS

3) before any data is submitted (using add button) all Textbox, Combobox must have a 'value' entered

any help in carrying out the above appreciated.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox1.TextLength <> 6 Then MsgBox ("this needs to be 6 characters")
    TextBox1.Text = UCase(TextBox1.Text)
End Sub

here's the first 2 parts
 
Upvote 0
I guess I could use...
Code:
DisplayMessage = "Please enter data into ALL fields Or press CLOSE to quit"
If Trim(Me.TextBox1.Value) = "" Then
  Me.TextBox1.SetFocus
  MsgBox DisplayMessage, vbExclamation, ("                 Express data")
and add each of the other Combobox and checkbox to this code, but as I have 15 in total thats a long bit of code to check all boxes are populated
 
Upvote 0
Hi,

could you adapt this which assumes the userform has 4 controls: Textbox1, Textbox2, Combobox1, Combobox2 :
Code:
Option Explicit

Private Sub ComboBox1_Change()
EnableDisableCommandButton
End Sub

Private Sub ComboBox2_Change()
EnableDisableCommandButton
End Sub

Private Sub TextBox1_Change()
With Application
    .EnableEvents = False
    TextBox1.Value = UCase$(TextBox1.Value)
    .EnableEvents = True
End With
EnableDisableCommandButton
End Sub

Private Sub TextBox2_Change()
EnableDisableCommandButton
End Sub

Private Sub UserForm_Initialize()
CommandButton1.Enabled = False
End Sub
Private Sub EnableDisableCommandButton()
With CommandButton1
    .Enabled = Len(TextBox1.Value) = 6

    If .Enabled Then
        .Enabled = TextBox2.Value <> "" _
                    And ComboBox1.Value <> "" _
                    And ComboBox2.Value <> ""
    End If
End With

End Sub

for the message you could always use the ControlTipText property to indicate requirements for each control
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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