Help Needed with Tab “Next Page†and “New Record†Buttons

  • Thread starter skyrise via AccessMonster.com
  • Start date
S

skyrise via AccessMonster.com

My database is divided out over 3 tab pages based on one Main Table and
related subforms.

I’m trying to come up with a “Next Page†command button script to move
between tabbed pages so that the user doesn’t have to scroll all the way back
to the top of the page to select the next tab.

I’m also trying to get the New Record button to go to a new record on Tab1
and place the cursor on Field2. Currently, the New Record button is located
on Tab3 and open a new record on Tab3.
 
A

Allen Browne

So the main form has a tab control with 3 pages:
- the main form is bound to the main table, with controls on the first page;
- the second page has a subform bound to a related table;
- the third page has another subform bound to a related table.

Place a command button on the 3rd page, below the subform (so it is not in
the subform, but appears below the subform.) Set these properties for the
button:
Caption &New Record
Name cmdNew
On Click [Event Procedure]

Click the Build button (...) beside the On Click property.
Access opens the code window.
Add 2 lines, like this:

Private Sub cmdNew_Click()
If Me.Dirty Then Me.Dirty = False
If Not Me.NewRecord Then RunCommand acCmdRecordsGotoNew
End Sub

How it works
==========
- Since the button is on the main form, Access will save any record you are
currently entering in the subform (or give you a message if it can't be
saved), before it moves focus to the button on the main form.

- Now that you are on the main form, it saves any incomplete entry there,
and then goes to a new record. (Since the button is on the main form, it's
the main form that goes to a new record.)

- Testing whether we are already at a new record avoids an error message if
you are already there.

- If you are faster with the mouse than the keyboard, you can use the Alt+N
hotkey to click the button (because of the ampersand in the Caption.) This
works even if you are in the subform at the time.

For the 'next page' button, if you put this button on the main form also,
all you have to do is SetFocus to something on that page of the tab
control. For example, if the first subform is named Sub1, the button's Click
event procedure would contain this line:
Me.Sub1.SetFocus
 
S

skyrise via AccessMonster.com

Looks like I got a couple of pieces of code to work for well for me on all
Tab pages.


For moving from tab to tab using command buttons (TY:don94403):

Private Sub btnGoToTab3_Click ()
Me!Field2.SetFocus
End Sub


For going to a new record using a command button (TY:Allen Browne):

Private Sub btnNewRecord_Click ()
If Me.Dirty Then Me.Dirty = False
If Not Me.NewRecord Then RunCommand acCmdRecordsGotoNew
End Sub
 
Top