Go to last record when selecting different pages on tab control subform

S

sandi

Hello group mates:
I've searched the groups but have only come up with half the answer.
Please forgive the stupid question.
I have a form with 2 pages in a tab control.
What I want to do is simple, when I hit page one, I would like to go to
the last record, same for page 2. Page 1 is in form format and 2 is in
datasheet format.

I have this code in my main form:

Private Sub Form_Current()
Me.cboLastName = CaseNumber 'synchronize txtboxes
On Error Resume Next
Dim frm As Form
Set frm = Me.SubVisits.Form 'this is Page 1
With frm
.RecordsetClone.MoveLast
.Bookmark = .RecordsetClone.Bookmark
End With
End Sub

This works great for the first page...
Should I use a select statement or dim another form for my second
subform?

Many thanks ahead of time!
Sandi
 
S

Sandra Daigle

I would move this code to a procedure that is called from the Current Event
of the form and the Change event of the Tab Control. In this procedure, you
can test the value of the Tab Control to determine which page is visible and
then execute the appropriate navigation code from there.

You don't need the object variable for the subform - just reference it
directly in the With Clause.

Note that on each of the cases below instead of using absolute page numbers
I get the page number by getting the pageindex of a named page. I do this
because the page index of a page changes if you reorder the pages but the
names don't change unless you change them. This just reduces maintenance and
prevents weird errors when you reorder the pages but forget to adjust the
code.

Select Case mIntCurTabPage
Case Me.TabCtl8.Pages("pgFirstPageName").PageIndex
With Me.SubVisits.Form
.RecordsetClone.MoveLast
.Bookmark = .RecordsetClone.Bookmark
End With
Case Me.TabCtl8.Pages("pgSecondPageName").PageIndex
With Me.SubOtherSubform.Form
.RecordsetClone.MoveLast
.Bookmark = .RecordsetClone.Bookmark
End With
End Select

Select Case me.MyTabCtl
 
S

sandi

Sandra said:
I would move this code to a procedure that is called from the Current Event
of the form and the Change event of the Tab Control. In this procedure, you
can test the value of the Tab Control to determine which page is visible and
then execute the appropriate navigation code from there.

You don't need the object variable for the subform - just reference it
directly in the With Clause.

Note that on each of the cases below instead of using absolute page numbers
I get the page number by getting the pageindex of a named page. I do this
because the page index of a page changes if you reorder the pages but the
names don't change unless you change them. This just reduces maintenance and
prevents weird errors when you reorder the pages but forget to adjust the
code.

Select Case mIntCurTabPage
Case Me.TabCtl8.Pages("pgFirstPageName").PageIndex
With Me.SubVisits.Form
.RecordsetClone.MoveLast
.Bookmark = .RecordsetClone.Bookmark
End With
Case Me.TabCtl8.Pages("pgSecondPageName").PageIndex
With Me.SubOtherSubform.Form
.RecordsetClone.MoveLast
.Bookmark = .RecordsetClone.Bookmark
End With
End Select

Select Case me.MyTabCtl

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hello group mates:
I've searched the groups but have only come up with half the answer.
Please forgive the stupid question.
I have a form with 2 pages in a tab control.
What I want to do is simple, when I hit page one, I would like to go
to the last record, same for page 2. Page 1 is in form format and 2
is in datasheet format.

I have this code in my main form:

Private Sub Form_Current()
Me.cboLastName = CaseNumber 'synchronize txtboxes
On Error Resume Next
Dim frm As Form
Set frm = Me.SubVisits.Form 'this is Page 1
With frm
.RecordsetClone.MoveLast
.Bookmark = .RecordsetClone.Bookmark
End With
End Sub

This works great for the first page...
Should I use a select statement or dim another form for my second
subform?

Many thanks ahead of time!
Sandi


I will try that straight away! Thanks!
 
S

sandi

As you can tell, I don't know nothing about coding, so your help is
greatly appreciated, even with typos.

I will try these changes.
Do I need to do any kind of dim statments?

(I'm not currently at the computer that has the database on it right
now so I can't test the code out yet.)
 
S

Sandra Daigle

No dims required. Let me know if you need any additional help. Good luck!
 

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