Button to go to a Text Box or label

B

Bob

Is it possible to create a button to go to a text box or label on the same
form!!...Thanks for any Help...bob







..........Jenny Vance
 
G

Guest

Hi Bob

Create the button and use this as the OnClick event

Private Sub ButtonName_Click()
Me.FieldName.SetFocus
End Sub


--
Wayne
Manchester, England.
Enjoy whatever it is you do
Scusate,ma il mio Inglese fa schiffo :)
Percio se non ci siamo capiti, mi mandate un
messagio e provero di spiegarmi meglio.
 
D

Dirk Goldgar

Bob said:
Is it possible to create a button to go to a text box or label on the
same form!!...Thanks for any Help...bob

What do you mean, "go to a text box"? A label can't receive the focus,
so I don't see how you could "go to" a label, whatever that may mean.
You can SetFocus to a text box, but I can't see why you would want a
button just to do that. So please explain what you're trying to do.
 
B

Bob

My from is so big I don't want to scroll down to my sub form at the bottom
of the page, so thought if I had a command button that would take me down
then I could have another to send me back to the top of the form, hope you
can understand my lack of understanding sorry,,,Bob
 
V

Van T. Dinh

I tend to design my Form so that it always fit on the screen. If I am short
of space, I tend to use TabControl to re-use the space on screen so that
users don't have to scroll up and down.

However, if you still want to go with your method and if the Control is
actually in the Subform, you need to set the Focus to the SubformControl
first then the Control in the Subform like:

Me.SubformControl.SetFocus
Me.SubformControl.Form.ControlOnSubformSetFocus

Note that you need to check the name of the SubformControl in the DesignView
of the main Form as this may or may not be the same as the Form you used as
the Subform.
 
B

Bob

Van can I just create a List box at the bottom of my form and assign the
command button to that focus then another list box at the top so I can go
from top to bottom using to command buttons, What sort of code would I need
to set focus on these list boxes.....Thanks for your help... bob
 
D

Dirk Goldgar

Bob said:
My from is so big I don't want to scroll down to my sub form at the
bottom of the page, so thought if I had a command button that would
take me down then I could have another to send me back to the top of
the form, hope you can understand my lack of understanding sorry,,,Bob

I see. In that case, you can use the SetFocus method, as others have
suggested, to move to specific controls. I agree with Van that you're
probably better off designing a form that will fit on most screens,
eliminating the need to scroll.
 
B

Bob

Cant really get it on the screen as it is a subform that has a lot of data
if I can say toggle up and down the form would be ideal,,Thanks Bob
 
D

Dirk Goldgar

Bob said:
Cant really get it on the screen as it is a subform that has a lot of
data if I can say toggle up and down the form would be ideal

See Wayne-I-M's original response. If you have two list boxes, one at
the top named, say, "lstTop", and one at the bottom named "lstBottom",
then you could have command buttons "cmdBottom" and "cmdTop" to set
focus to each of them, with code like this:

Public Sub cmdBottom_Click()
Me!lstBottom.SetFocus
End Sub

Public Sub cmdTop_Click()
Me!lstTop.SetFocus
End Sub
 
B

Bob

Thanks Dirk, I am going to re arrange my form to see if I can get it on one
screen taking both of your advise....Thanks Bob
 
J

JK

Bob,

Just create a Command button and use the onClick event.

Private Sub MyNewButton_Click()

DoCmd.GoToControl "My Text Box"

End Sub

You cannot Go to a label as already mentioned here (there is no reason to do
so).


If your text box is on a subfrom:

Private Sub MyNewButton_Click()

DoCmd.GoToControl "SubFormName"
Form("SubFormName").SetFocus
'Note "Form" in singular
DoCmd.GoToControl "My Text Box" 'which is on subform

End Sub

To go back from the subForm, create another Command Button on your *Main*
form and:

Private Sub AnotherCmd_Click()
Me.Dirty=False
DoCmd.SelectObject acForm, "MainForm name"
DoCmd.GoToControl "Somewhere at the top of the main Form

End Sub

Regards
Jacob
 

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