Pointing specific textbox

B

Bobby

Hi,
Could someone tell how to initialize or place the cursor in a specific
box on a userform, when I open the userform containing 4 text boxes.
By default it goes in the first one.

Thank's ahead.
 
R

Rick Rothstein

Just use the TextBox's SetFocus method. For example, if you wanted TextBox3
to have focus...

Private Sub UserForm_Initialize()
TextBox3.SetFocus
End Sub
 
B

Bobby

Just use the TextBox's SetFocus method. For example, if you wanted TextBox3
to have focus...

Private Sub UserForm_Initialize()
  TextBox3.SetFocus
End Sub

--
Rick (MVP - Excel)







- Show quoted text -

Great! Thank's

How can I get the info selected after having the cursor in that
specific box,so when I start typing the new number is written?
Thank.
 
R

Rick Rothstein

Could someone tell how to initialize or place the cursor in a specific
Great! Thank's

First off, it is always a good idea to post in the same way as the person
who responded to you (that is, keep posting all new responses to the top or
bottom, but alternate between the top and the bottom as you did)... it keeps
the flow of responses in an easy to follow order so people viewing the
thread in the future can follow it more easily). I have repaired this
message to bottom post to match your response, but in the future, it would
be a better idea for you to adopt the method used by the person who
responded to you....
How can I get the info selected after having the cursor in that
specific box,so when I start typing the new number is written?

So the new number is written **where**... to a Label on the UserForm, a cell
in the worksheet, somewhere else? The code depends on how you want the user
to interact with the UserForm. Are you just going to dump whatever the user
types directly into wherever you want to display it at? Are you going to
validate the entry first (if you are looking for a number and the user types
"ABC", how are you going to handle that)? Are you going to use an OK button
to signal that it is time to put the text wherever it will finally be
placed... or will just the action of moving the focus to another control or
closing the UserForm be the action that initiates the moving of the text to
wherever it will finally be placed? When you work in the VB world, there is
lots more to consider and control... you kind of have to have an overall
idea what you want to do and how you want to do it or you will be tearing
apart and rebuilding code all over the place.
 
B

Bobby

TRY THIS
Private Sub UserForm_Initialize()
TextBox3.SetFocus
End Sub






- Show quoted text -

Rick, to apply your recommandation regarding the usage of the group,
there are 3 buttons:

Reply Reply to author Forward

Which one should I use?

Regarding my last question, there no need for validation in this
Userform. Just an assignment to specific cell.
Thank's and regards.
 
R

Rick Rothstein

Bobby said:
Rick, to apply your recommandation regarding the usage of the group,
there are 3 buttons:

Reply Reply to author Forward

Which one should I use?

Regarding my last question, there no need for validation in this
Userform. Just an assignment to specific cell.
Thank's and regards.

In that case, I would just assign the TextBox's ControlSource property to
the cell you want to display the text in. You will find the ControlSource
property in the Project Properties window... just select the TextBox first,
then type in the address (along with its worksheet) in the space to the
right of the ControlSource property; for example, Sheet3!H7. You can do that
for each TextBox (using a different cell address, of course)... then, when
the user hits the Enter key or moves the focus to another control, the text
in the TextBox will be entered into the specified cell.
 

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