[Last Call] Learn how to a build a cloud-first strategyRegister Now


Moving between Tab Control subforms

Posted on 2004-11-16
Medium Priority
Last Modified: 2012-06-27
I have a tab control on a form which has two pages. On each page there is a continuous subform (which can get quite long) and both subforms recordsource is the same table. What I would like to be able to do is scroll down the first subform and highlight a record using the record selector button and then click on the second tab. Now, I can then get it to goto the same record on the second tab, but the record goes to the top of the subform. I would like to keep the record in the same position as the one chosen on the first subform. Is this possible? And if so how?

Thanks in advance,

Question by:mcdermon
  • 2
LVL 58

Accepted Solution

harfang earned 1000 total points
ID: 12594047
Everything is possible... some things are just a little bit harder :)

The properties available are scarce: .CurrentSectionTop indicates the distance between the active instance of the subform and the top of the form. This can provide the number of rows above the current selection. But there is no built-in method to scroll the window. Of course, you could find the WinAPI function for that...

Meanwhile, you can move the selection to force a scroll. That works only if there are records to select of course.

Toying with the idea, I came up with this. (Two subforms, both in datasheet view, same number of records, and a button to synchronize subform2 with subform1.)

Not ideal, but the best I could do without accessing the scroll bars.

Private Sub cmdSynch_Click()

    Dim frm1 As Form, frm2 As Form
    Dim intTest As Integer
    Set frm1 = subSynch1.Form
    Set frm2 = subSynch2.Form
    ' just looking nice while debugging
    frm1.SelLeft = 1: frm1.SelWidth = 10
    ' synchronize record numbers
    frm2.Recordset.AbsolutePosition = frm1.Recordset.AbsolutePosition
    ' try to scroll upwards
    For intTest = 1 To frm2.Recordset.AbsolutePosition
        If frm2.CurrentSectionTop >= frm1.CurrentSectionTop Then _
            Exit For
        With frm2.Recordset
            .AbsolutePosition = .AbsolutePosition - intTest
            .AbsolutePosition = .AbsolutePosition + intTest
        End With
    Next intTest
    ' try to scroll downwards
    For intTest = 1 To frm2.Recordset.RecordCount - frm1.SelTop
        If frm2.CurrentSectionTop <= frm1.CurrentSectionTop Then _
            Exit For
        With frm2.Recordset
            .AbsolutePosition = .AbsolutePosition + intTest
            .AbsolutePosition = .AbsolutePosition - intTest
        End With
    Next intTest
    ' just looking nice while debugging
    frm2.SelLeft = 1: frm2.SelWidth = 10
End Sub

Hope this helps!

Author Comment

ID: 12602799
Thank you so much! That works brilliantly even in continuous form view. And such a quick response. Fan-bleedin-tastic!!!

LVL 58

Expert Comment

ID: 12603232
Well, I'm glad you like it :) cheers!

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question