A HELP BOX

L

LEU

I have a form that opens from a document. When you go to enter your name, it
needs to be in a set format. Is there a way that when I’m in the name textbox
a help or information balloon opens with the following : “Enter your First
name, CtrlTab twice, your Middle Initial, CtrlTab once, Last Name†and then
closes when they go to the next box?
 
J

Jay Freedman

I have a form that opens from a document. When you go to enter your name, it
needs to be in a set format. Is there a way that when I’m in the name textbox
a help or information balloon opens with the following : “Enter your First
name, CtrlTab twice, your Middle Initial, CtrlTab once, Last Name” and then
closes when they go to the next box?

What kind of "form" are we talking about here? A protected document, containing
form fields? An unprotected document containing a table (guessing because of the
CtrlTab)? A userform? The answer is different for each of these.

Also, it may be possible to avoid the need for an instruction popup by designing
the form properly. What "properly" means depends on how you're going to use the
completed document -- why do you need this specific format?
 
J

Jay Freedman

The simplest solution for a userform is to put the instructions into a label
directly on the userform surface. If you want to get fancy, the _Exit()
procedure of the text box could set the label's .Visible property to False when
the user leaves the box; and it could also validate the user's entry and set the
Cancel argument to False so they can't exit until the format is correct.
 
L

LEU

I'm not sure what you are saying. Are you saying that when I would enter the
textbox a label box would show up that would display the correct format and
then when I would leave the text box the labelbox would turn invisible?
 
J

Jay Freedman

You could do that. I had assumed that the label would be visible initially when
the userform appears, not that it would be made visible on entering the text
box. But if you want to do that, certainly you could put a statement into the
text box's _Enter() procedure to set the label's .Visible property to True.

Try it, see how it looks to you.
 
L

LEU

How would you write it?




Jay Freedman said:
You could do that. I had assumed that the label would be visible initially when
the userform appears, not that it would be made visible on entering the text
box. But if you want to do that, certainly you could put a statement into the
text box's _Enter() procedure to set the label's .Visible property to True.

Try it, see how it looks to you.
 
G

Greg Maxey

Thinking it might be past Jay's bedtime I will step in. Something like this
maybe:

lblDescriptive is the name of the descriptive label placed near the textbox.

Private Sub UserForm_Initialize()
With Me.lblDescriptive
.Visible = False
.Caption = ""
.ForeColor = &H80000012
End With
End Sub

'Show the decriptive label on entry to the text field.

Private Sub TextBox1_Enter()
With Me.lblDescriptive
.Visible = True
.Caption = "Enter your name in this format: ""First name, CtrlTab twice,
your Middle Initial, CtrlTab once, Last Name"""
.ForeColor = wdColorBlue
End With
End Sub

'Validate the entry on exit

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With Me.TextBox1
If Not .Text Like "[A-Z]*" & vbTab & vbTab & "[A-Z]" & vbTab & "[A-Z]*" Then
Cancel = True
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
With Me.lblDescriptive
.Caption = "Wrong format!! Enter your name in this format: ""First
name, CtrlTab twice, your Middle Initial, CtrlTab once, Last Name"""
.ForeColor = wdColorRed
End With
End If
End With
End Sub

'Restore label when user begins correction.
Private Sub TextBox1_Change()
With Me.lblDescriptive
.Visible = True
.Caption = "Enter your name in this format: ""First name, CtrlTab twice,
your Middle Initial, CtrlTab once, Last Name"""
.ForeColor = wdColorBlue
End With
End Sub
How would you write it?

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 
J

Jay Freedman

For this example, I'm assuming a userform with three text boxes (with the
default names TextBox1, TextBox2, and TextBox3, although you should rename them
to reflect their purpose) and one label named Label1 (again, renamed to reflect
purpose, and you'd probably have other labels as well). The user is expected to
enter their name in TextBox2 in the format explained by Label1.

These two procedures will do what you ask, including the validation of the
user's entry in the text box:

Private Sub TextBox2_Enter()
Label1.Visible = True
End Sub

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
' validation
If Not TextBox2.Value Like "*" & vbTab & vbTab & "*" & vbTab & "*" Then
MsgBox "Invalid format. Please follow the instructions."
Cancel = True
Else
Label1.Visible = False
End If
End Sub

If you don't want the explanation to be visible when the userform first appears,
you can set its Visible property to False in the Properties pane of the
designer, or you can set it through code with this procedure:

Private Sub UserForm_Activate()
Label1.Visible = False
End Sub


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top