command buttons for different text boxes

N

Nick T

Hi,

Could anyone help with the below please???



Hi,
Thanks for the help.
Your suggestion works, but not how i want it to.
Ill try explaining a little better:

I have 10 command buttons on a form and 20 text boxes. To make my system
user-friendly, i want a user to use the command buttons to input data into
the text boxes. The command buttons are labelled 1 to 10 and when clicked,
the command button will imput the relivant number into a text box.

I want the command buttons to put their number into only one text box at a
time, but this text box could be any of the 20 text boxes i have on my form.
So really, the command button needs to put its number into the text box which
has the cursor in it.

Hope this makes sense & any help is greatly appreciated.

Nick
 
D

Douglas J. Steele

If you've clicked on a command button, the cursor won't be in any text box:
focus will have moved to the command button. You could use the
PreviousControl property, but how will you know for certain that the control
where focus was before they clicked on the command button is a legitimate
place to put a value?
 
N

Nick T

The values which the comand buttons shall be putting into the text boxes will
all be numbers - all other data input will be text. Could i use the 'Auto
tab' function?
For eg. The operation will be text in 'text box A' followed by a number in
'text box b' then text in 'text box c' and number in 'text box d'.
I want all numbers to be inputed using the same 'number key pad' which i
have made using the command buttons.

Following an input into any of the text boxes whether it be text or number,
could i use the SetFocus function AfterUpdate??

Any suggestions or simply not possible??

Many thanks
 
R

Rastro

If it helps put this code in each button click event:

If Not Screen.PreviousControl.ControlType = 109 Then Exit Sub

strTextBoxName = Screen.PreviousControl.Name
strButtonText = ActiveControl.Caption
strButtonName=ActiveControl.Name
Controls(strTextBoxName).SetFocus
Controls(strTextBoxName) = strButtonText
Controls(strButtonName).SetFocus

-------------------

This will check if the previous control was a textbox (109) and exit if not.
If yes then will put the strButtonText in the textbox that had the focus
when the button was clicked. This process means move the focus to the
textbox, set the value and return the focus to the button. The strButtonText
is the value that the button has and need to set in the text box.
 
N

Nick T

Hi,
Thanks for the great help - nearly there i think so hope you can help a
little more.

I have put the code into the command buttons code and it works as you say,
however, i have 10 command buttons which effectively i want to use to enter
any 'string' of numbers into a set text box. eg. if i want to write the
number 555 into a text box, then i want to click the no. 5 command button
three times.

Unfortunately, the code doesnt allow this, so hope you can help.

Lastly, once the correct number has been entered into the desired text box,
i shall have another command button next to it, which when clicked will
simply SetFocus to the next text box i want to input a 'string' of numbers
into.

Look forward to hearing from you.

Thanks
 

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