[Access 2007] Table of contents on form

bodylojohn

Registered User.
Local time
Today, 14:25
Joined
Dec 28, 2005
Messages
205
Hello,

I have a question but I don't know how to name it.
My question is probably anwsered somewhere on this forum but I just don't know how te call it.

Ok...here we go:
I have a form. On that form there is a long list of controls.
The controls are nicely grouped.

I want to make a list of the several groups and when I click an item in the list (of whatever is best to use for this) and I get taken to the place on the form where my group is.

that way the user doesnt need to scroll all the way down.

Thanks in advance guys...
 
I would suggest using a Label for each thing you want to allow the user to jump to. Then, in the OnClick event of that label, you would use code like this:
Code:
MySelectedControlName.SetFocus
That's going to be a lot of coding if you have a lot of controls, which it sounds like you have. To make your life much easier, I would suggest, rather than using what I first suggested, a function that will look at the active control, use the value in that control as the source for where to jump, then issue the .SetFocus with that. Therefore, use a text box, without a label, for each "Table of Contents" entry. Set that text box to something like: ="ControlNameToSetFocus". Now set the OnClick property of each of these textboxs to: =funcSetFocus(). Then the funcSetFocus() function would look like this:
Code:
Function funcSetFocus()
Dim ctl As Control
  Set ctl = Screen.ActiveControl
  Me.Controls(ctl).SetFocus
End Function
Be sure to change the "ControlNameToSetFocus" to the actual name of the control you want to receive the focus. I have tested this and it works. I do assume something will not go right for you, so if it does not work the first time, please post the code you have used. Not only for the function, but also for one of the "table of contents" entries, and how you have coded the OnClick property for that same "table of contents" entry.
 
I would suggest using a Label for each thing you want to allow the user to jump to. Then, in the OnClick event of that label, you would use code like this:
Code:
MySelectedControlName.SetFocus
That's going to be a lot of coding if you have a lot of controls, which it sounds like you have. To make your life much easier, I would suggest, rather than using what I first suggested, a function that will look at the active control, use the value in that control as the source for where to jump, then issue the .SetFocus with that. Therefore, use a text box, without a label, for each "Table of Contents" entry. Set that text box to something like: ="ControlNameToSetFocus". Now set the OnClick property of each of these textboxs to: =funcSetFocus(). Then the funcSetFocus() function would look like this:
Code:
Function funcSetFocus()
Dim ctl As Control
  Set ctl = Screen.ActiveControl
  Me.Controls(ctl).SetFocus
End Function
Be sure to change the "ControlNameToSetFocus" to the actual name of the control you want to receive the focus. I have tested this and it works. I do assume something will not go right for you, so if it does not work the first time, please post the code you have used. Not only for the function, but also for one of the "table of contents" entries, and how you have coded the OnClick property for that same "table of contents" entry.

Thank you very much for your help.

I am going to use the setfocus solution.
Because I dont have that much groups.
This encounters another problem which I will place in a seperate topic.
 

Users who are viewing this thread

Back
Top Bottom