Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

command buttons for different text boxes

17 views
Skip to first unread message

Nick T

unread,
May 12, 2008, 4:52:02 PM5/12/08
to
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

"Al Campagna" wrote:

> Nick,
> You wrote...
> > Me.order = Me.order & "1"
> > This code for my command button 1 will put a "1" into my text box called
> > "order"
> Not really true. It appends a text 1 to whatever is already in Order.
>
> > However, i want the same command button to be able to put the same
> > information into other text boxes as well.
> If that's true then using the Click event of your button...
> Private Sub cmd1_Click()
> SomeField1 = Field1 & "1"
> SomeField2 = Field2 & "1"
> SomeField3 = Field3 & "1"
> ' etc... for all fields
> End Sub
> --
> hth
> Al Campagna
> Microsoft Access MVP
> http://home.comcast.net/~cccsolutions/index.html
>
> "Find a job that you love... and you'll never work a day in your life."
>
>
> "Nick T" <Ni...@discussions.microsoft.com> wrote in message
> news:D88A379D-4254-4E33...@microsoft.com...
> > Hi,
> > I have a database which uses command buttons to input numbers into a text
> > box all on one form.
> > I can currently use command buttons to do this, however for obvious
> > reasons
> > as you will see by the code, the command button will only put a number
> > into
> > one text box.
> > Current code:
> > Me.order = Me.order & "1"
> >
> > This code for my command button 1 will put a "1" into my text box called
> > "order"
> >
> > However, i want the same command button to be able to put the same
> > information into other text boxes as well.
> > Eg. what ever text box my cursor is in, i want the command button to put
> > the
> > number in when clicked.
> > Any suggestions on the code i should use??
> >
> > Many thanks
> > Nick

Douglas J. Steele

unread,
May 12, 2008, 5:03:08 PM5/12/08
to
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?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Nick T" <Ni...@discussions.microsoft.com> wrote in message

news:9FFA805A-2538-4994...@microsoft.com...

Nick T

unread,
May 12, 2008, 5:22:01 PM5/12/08
to
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

Rastro

unread,
May 12, 2008, 6:33:41 PM5/12/08
to
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.

"Nick T" <Ni...@discussions.microsoft.com> escribió en el mensaje de
noticias:ADDBD6D2-BD49-4653...@microsoft.com...

Nick T

unread,
May 13, 2008, 6:01:02 PM5/13/08
to
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

0 new messages