Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,570
- Office Version
- 365
- 2016
- Platform
- Windows
On my userform, a combobox change event is triggered when the user changes the value from the dropdown. If the user selects "Other", this code is executed:
The code in purple effectively unlocks the previously locked textbox, sets the focus, gives it a default value (to be replaced by the user), changes the font to a grey colour and italicized and highlights the text allowing the user to over-write the default. Because the focus is set automatically to this text box, the user can start typing to over write the default text.
A change event changes the font to a more appropriate black and non-italicized font.
My issue comes from the error checking routine upon the exit event of this text. On exit, my code assess the entry to make sure it's not blank, that it's not the default, and that it takes the proper form (with a comma and space)
What I would like to do is mimic the behaviour of this textbox as is done initially on the combobox change. (ie set default value, change font, and highlight text for over writing). This existing code isn't living up to that expectation, specifically the highlighting in preparation for over writing. As it stands now, the default text is placed, the font applied, but the user has to click into the textbox, manually highlighting the text to delete it or over write it.
Any help would be greatly appreciated!!
Rich (BB code):
Private Sub uf1cbx1_operatorini_Change()
If uf1cbx1_operatorini.Value = "Other" Then
With uf1lbl1_name
.Locked = False
.SetFocus
.Text = "Surname, Given"
.ForeColor = RGB(220, 220, 220)
.Font.Italic = True
.SelStart = 0
.SelLength = Len(.Text)
End With
Else
uf1lbl1_name = Application.WorksheetFunction.VLookup(uf1cbx1_operatorini.Value, Range("uf1rng_staff"), 2, False)
End If
opscount = opscount + 1
If opscount = 4 Then
uf1cbtn1_submit.Enabled = True
MultiPage1.Enabled = False
End If
End Sub
The code in purple effectively unlocks the previously locked textbox, sets the focus, gives it a default value (to be replaced by the user), changes the font to a grey colour and italicized and highlights the text allowing the user to over-write the default. Because the focus is set automatically to this text box, the user can start typing to over write the default text.
A change event changes the font to a more appropriate black and non-italicized font.
Rich (BB code):
Private Sub uf1lbl1_name_change()
With uf1lbl1_name
.Font.Italic = False
.ForeColor = RGB(0, 0, 0)
End With
End Sub
My issue comes from the error checking routine upon the exit event of this text. On exit, my code assess the entry to make sure it's not blank, that it's not the default, and that it takes the proper form (with a comma and space)
Rich (BB code):
Private Sub uf1lbl1_name_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(uf1lbl1_name) = 0 Then
With uf1lbl1_name
.Text = "Surname, Given"
MsgBox "Improper name entry." & Chr(13) & "'Surname, Given'", , "ERROR"
.SetFocus
.Font.Italic = True
.SelStart = 0
.SelLength = Len(uf1lbl1_name.Text)
End With
ElseIf InStr(uf1lbl1_name, ", ") < 1 Then
With uf1lbl1_name
.Text = "Surname, Given"
MsgBox "Improper name entry." & Chr(13) & "'Surname, Given'", , "ERROR"
.SetFocus
.Font.Italic = True
.SelStart = 0
.SelLength = Len(uf1lbl1_name.Text)
End With
ElseIf uf1lbl1_name.Text = "Surname, Given" Then
With uf1lbl1_name
.Text = "Surname, Given"
MsgBox "Improper name entry." & Chr(13) & "Please use a real name.", , "ERROR"
.SetFocus
.Font.Italic = True
.SelStart = 0
.SelLength = Len(uf1lbl1_name.Text)
End With
End If
End Sub
What I would like to do is mimic the behaviour of this textbox as is done initially on the combobox change. (ie set default value, change font, and highlight text for over writing). This existing code isn't living up to that expectation, specifically the highlighting in preparation for over writing. As it stands now, the default text is placed, the font applied, but the user has to click into the textbox, manually highlighting the text to delete it or over write it.
Any help would be greatly appreciated!!