Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with using tab controls

Status
Not open for further replies.

Klssri

MIS
Nov 5, 2001
62
US
I have developed a form that has several tabs. I have set up buttons on each tab sheet to go to the next tab sheet. On the last sheet, after you enter the information and hit enter, it does go to the next record but stays on the last sheet. Is there a way to make it start over at the beginning? Any ideas.
 
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyEnter Then Page1.SetFocus

End Sub

Hope this helps. Let me know if not.
 
Forgive my ignorance, I am not that familiar with Access. Where exactly do I use this. Are pages the same as tab sheets?
 

Hi:

Just strikes me...isn't it redundant to use a button to go to the next tab? That's what the tabs are for in the first place. Unless each page is longer than the screen...in that case, O.K. Gus Brunston [glasses] An old PICKer, using Access2000.
 

Hi:

(With apologies to Shake412 for butting in...)

Right click on the control (button).
Select "Properties".
Select "Event".
Select "On Key Up".
At the cursor, enter the code Shake gave you.
Substitute the name of your control (button) for "Text1".
(You can find the name of your control in the property sheet, "Other".)
Code:
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    
    If KeyCode = vbKeyEnter Then Page1.SetFocus
    
End Sub
Gus Brunston [glasses] An old PICKer, using Access2000.
 

Hi one more time:

Sorry, I left out: When you select "On Key Up", you will see an ellipsis (...) on the right side of the property sheet. Click on it and then enter the code. You don't have to substitute anything...the right name of your control will already have been entered by Access.

Forgive me for not being more clear in the last post.
Gus Brunston [glasses] An old PICKer, using Access2000.
 
The button actually is very useful when you are doing alot of data entry. While tabing through fields you can tab to the button and press enter rather than having to use your mouse to click on the tab itself. The way I have it set up the person doing the data entry should not have to touch the mouse until they are done. I will try your advice on the control and see what happens.
Thanks for the help.
 
I tried the suggestion given and am getting the following error message "Compile Error: Variable not defined". The code box opens up then and "Private Sub Command333_KeyUp(KeyCode As Integer, Shift As Integer)" is highlighted. This is what I typed in after that line, as suggested.
If KeyCode = vbKeyReturn Then Page1.SetFocus
End Sub
Any ideas of why I am getting this.
 
Hi:

Sorry, I couldn't reproduce your error.

Also, I couldn't make a button work as you wish it to.

I found this in Running MS 2000:
"Note that there's no programming required to implement tab selection and data display." and "...some ActiveX controls require Visual Basic code to make them work well. The tab control works without any programming..."

Also, in Help, "...You can't use the GoToPage action (in a macro) in the following cases...To move the focus from one page to another within the Tab control."


I'm beginning to think that there is no code you can use to move between the pages of a tab control.

The user can move between pages with Control>Tab.

Sorry I couldn't be of more help. Maybe someone else...
Gus Brunston [glasses] An old PICKer, using Access2000.
 
Hi:

I can't leave this alone!

This WILL work (without a button) to allow the user to continue from page to page of the tab control without leaving the keyboard:

Assume:
the last control on Page 1 is named "txtLast1".
the first control on Page 2 is named "txtFirst2". etc.

In the "On Exit" event for txtLast1, enter the following:
Code:
Private Sub txtLast1_Exit(Cancel As Integer)
On Error GoTo txtLast1_Exit_Err
    DoCmd.GoToControl "txtFirst2"
txtLast1_Exit_Exit:
    Exit Sub
txtLast1_Exit_Err:
    MsgBox Error$
    Resume txtLast1_Exit_Exit
End Sub

When the focus is on the control "txtLast1", when the user touches either the tab key or the enter key, the focus will move to "txtFirst2", on Page 2 of the tab control. If the user needs to go back to another control on Page 1, the mouse would have to be used, I think.

You would then have to put similar code in the On Exit event of the last control of each page of the tab control;
of course, inserting the appropriate control names to link each page with the next.

Not what you asked for (no button), but it will flow.

If you wished, I could attach to an email the (very small) database that I thoroughly tested this with.



Gus Brunston [glasses] An old PICKer, using Access2000.
 
I am using Access 97. The buttons are not my real problem. They are working from going from tab sheet to tab sheet. On the button go to properties - event - onclick. I set up a macro to GoToControl and put in the name of the control on the next tab sheet. All the user has to do is hit tab to go through the fields until the button has focus and then hit enter and it goes to the next tab sheet, or for that matter wherever I want it to go. My problem is when they are done with entering a particular record and need to go to the next record, I can't get it to go back to the first tab sheet, it is staying on the last tab sheet.
 
For "txtFirst3" substitute the name of the last control on the last page of your tab control. For "txtFirst1" substitute the name of the first control on the first page of your tab control.

In the last control on the last page enter this in the On Exit event:
Code:
Private Sub txtFirst3_Exit(Cancel As Integer)
    On Error GoTo txtFirst3_Exit_Err    
    'Will save your record
    DoCmd.DoMenuItem acFormBar, acRecordsMenu,_
      acSaveRecord, , acMenuVer70
    'Will open a new record
    DoCmd.GoToRecord , , acNewRec   
    'Will set the focus to 'txtFirst1'
    DoCmd.GoToControl "txtFirst1"
txtFirst3_Exit_Exit:
    Exit Sub
txtFirst3_Exit_Err:
    MsgBox Error$
    Resume txtFirst3_Exit_Exit
End Sub

After entering the last information for one record, this will save that record, open a new record, and return the user to the first control on page 1.

I don't know of any reason this won't work in Access97, but I've never used anything but A2K. But maybe the menu version number is different. You could find out by creating a command button with the wizard and then looking at the code for that button. I dunno...
Gus Brunston [glasses] An old PICKer, using Access2000.
 
Thank You Gus, that last tip did the trick. Everything is working fine now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top