[AccessD] Control which record shows at top of subform

Dan Waters dwaters at usinternet.com
Wed Nov 15 10:29:45 CST 2006


Hi Lonnie,

Long ago I found code to do this from a site somewhere.  I'll post it here.
I haven't used it but you may be able to.

---------------------------------------------------------------------

Option Compare Database
Option Explicit

Private Const GWL_STYLE = (-16)

' GetWindow() Constants
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

' Scroll Bar Constants
Private Const SB_HORZ = 0
Private Const SB_CTL = 2
Private Const SB_VERT = 1

' ScrollInfo fMask's
Private Const SIF_RANGE = &H1
Private Const SIF_PAGE = &H2
Private Const SIF_POS = &H4
Private Const SIF_DISABLENOSCROLL = &H8
Private Const SIF_TRACKPOS = &H10
Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)

' Scroll Bar Styles
Private Const SBS_HORZ = &H0&
Private Const SBS_VERT = &H1&

Private Declare Function apiGetScrollInfo Lib "user32" Alias "GetScrollInfo"
(ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
Private Declare Function apiGetWindow Lib "user32" Alias "GetWindow" (ByVal
hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function apiGetWindowLong Lib "user32" Alias
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long)
As Long

Private Type SCROLLINFO
    cbSize As Long
    fMask As Long
    nMin As Long
    nMax As Long
    nPage As Long
    nPos As Long
    nTrackPos As Long
End Type

Public Function GetScrollBarPosition(frm As Form) As Long
On Error GoTo EH

    ' Return ScrollBar Thumb position for the Vertical Scrollbar attached to
the Form passed to this Function.

    Dim hWndSB As Long
    Dim lngRet As Long
    Dim sinfo As SCROLLINFO

    '-- Init SCROLLINFO structure
    sinfo.fMask = SIF_ALL
    sinfo.cbSize = Len(sinfo)
    sinfo.nPos = 0
    sinfo.nTrackPos = 0

    '-- Call function to get handle to
    '-- ScrollBar control if it is visible
    hWndSB = IsScrollBar(frm)
    If hWndSB = -1 Then
        GetScrollBarPosition = False
        Exit Function
    End If

    '-- Get the window's ScrollBar position
    lngRet = apiGetScrollInfo(hWndSB, SB_CTL, sinfo)
    GetScrollBarPosition = sinfo.nPos + 1

    Exit Function

EH:
    Application.Echo True

End Function

Private Function IsScrollBar(frm As Form) As Long
On Error GoTo EH

    Dim hWnd_VSB As Long
    Dim hwnd As Long

    '-- Get ScrollBar's hWnd
    hwnd = frm.hwnd

    '-- Get first Child Window of the FORM
    hWnd_VSB = apiGetWindow(hwnd, GW_CHILD)

    '-- Walk through every sibling window of the Form
    Do
        If GetClassName(hWnd_VSB) = "scrollBar" Then
            If apiGetWindowLong(hWnd_VSB, GWL_STYLE) And SBS_VERT Then
                IsScrollBar = hWnd_VSB
                Exit Function
            End If
        End If

        '-- Get the NEXT SIBLING Window
        hWnd_VSB = apiGetWindow(hWnd_VSB, GW_HWNDNEXT)

        '-- Start the process from the Top again
        '-- Really just an error check
    Loop While hWnd_VSB <> 0

    '-- If no vertical ScrollBar control is currently visible for this Form
then
    IsScrollBar = -1

    Exit Function

EH:
    Application.Echo True

End Function

Private Function GetClassName(hwnd As Long) As String
On Error GoTo EH

    Dim strBuffer As String
    Dim lngLen As Long

    Const MAX_LEN = 255

    strBuffer = Space$(MAX_LEN)
    lngLen = apiGetClassName(hwnd, strBuffer, MAX_LEN)
    If lngLen > 0 Then
        GetClassName = Left$(strBuffer, lngLen)
    End If

    Exit Function

EH:
    Application.Echo True

End Function

-------------------------------------------------------------------------

Dan Waters


-----Original Message-----
Subject: [AccessD] Control which record shows at top of subform

I have a subform and have buttons that navigate to certain records.
Sometimes when the requested record is located it appears in the middle of
the subform.

I have the subform sized to show a certain amount of records at a time and
want the "found" record to be at the top of my list.

Is this possible?
 








May God bless you beyond your imagination!
Lonnie Johnson
ProDev, Professional Development of MS Access Databases
Visit me at ==> http://www.prodev.us


 
____________________________________________________________________________




More information about the AccessD mailing list