If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Set the focus to the top of the form that has a tabcontrol
Hi
I have a form which consists of a tab control. When users switch between tabs, I want to set the focus of the entire form to the top of the form each time instead of where they let the form on their previous visit. Is this possible? I tried to set the focus to the top of the form by using the following: Me.StudentID.SetFocus But it doesn't work. I'm not sure of where I should put the code. Is this the right one to use or would something else be better? I also read somewhere in one of the forums I can set the focus first to the mainform by using Forms![MainFormName].Set focus But I can't figure out where it should go? Thank you for your help in advance. |
#2
|
|||
|
|||
Set the focus to the top of the form that has a tabcontrol
"but it doesn't work" doesn't give us much to go on.
Clearly, you understand that you set the focus to a control, not to the "top of the form". Is [StudentID] the name of your control, or the field underlying it? Have you tried: Me!StudentID.SetFocus (the "!" tells Access that the object is one YOU created) Are there subforms involved? Where are you trying to use that code? More info, please... Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "forest8" wrote in message ... Hi I have a form which consists of a tab control. When users switch between tabs, I want to set the focus of the entire form to the top of the form each time instead of where they let the form on their previous visit. Is this possible? I tried to set the focus to the top of the form by using the following: Me.StudentID.SetFocus But it doesn't work. I'm not sure of where I should put the code. Is this the right one to use or would something else be better? I also read somewhere in one of the forums I can set the focus first to the mainform by using Forms![MainFormName].Set focus But I can't figure out where it should go? Thank you for your help in advance. |
#3
|
|||
|
|||
Set the focus to the top of the form that has a tabcontrol
You should be able to set the focus in the Change event of the tab control,
assuming there is a text box or other control to receive the focus at the top of the form. Your code should work if there is a text box named StudentID. If it is the name of both the field and the text box I would change the text box name to something like txtStudentID, but it isn't absolutely necessary to do that. It gets a little more complicated if you wish to set the focus to a different text box on each tab page. You could do something like this in the tab control's Change event (assuming the tab control is named tabMain: Select Case Me.tabMain.Pages.Item(Me.tabMain.Value).Caption Case "FirstTab" Me.Text1.SetFocus Case "Second Tab" Me.Text2.SetFocus End Select Me.tabMain.Value gives you the index number of the tab page. They are numbered starting at 0. If you click on the first tab, Access will insert 0 into the expression, so it is the same as if you wrote: Select Case Me.tabMain.Pages.Item(0).Caption If you click on the second tab, it is the same as: Select Case Me.tabMain.Pages.Item(1).Caption By using Me.tabMain.Value to fetch the number, you will return the caption of whatever tab you click. You could simplify the expression and just use the index number: Select Case Me.tabMain.Value Case 0 Me.Text1.SetFocus etc. However, using the caption may make it easier to folow the code as you write it, and especially when you look at it later. forest8 wrote: Hi I have a form which consists of a tab control. When users switch between tabs, I want to set the focus of the entire form to the top of the form each time instead of where they let the form on their previous visit. Is this possible? I tried to set the focus to the top of the form by using the following: Me.StudentID.SetFocus But it doesn't work. I'm not sure of where I should put the code. Is this the right one to use or would something else be better? I also read somewhere in one of the forums I can set the focus first to the mainform by using Forms![MainFormName].Set focus But I can't figure out where it should go? Thank you for your help in advance. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/201003/1 |
Thread Tools | |
Display Modes | |
|
|