Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002

    Question Unanswered: Determining position in listbox

    In my Access 2000 application, I need to be able to determine what entries are currently being displayed in a listbox regardless of which row in the listbox is selected. For example, if the first row in the listbox is selected but the user scrolls down so that entries 15-25 are showing in the listbox, I need to know that those are the entries being displayed. Access listboxes (at least the ones in Access 2000) do not have a TopIndex property like VB does and the Access listboxes do not seem to respond to the LB_GETTOPINDEX message (the SendMessage function just returns 0). Is there any way to determine this information for an Access listbox?

  2. #2
    Join Date
    Mar 2005
    You will find the answer from Stephen Lebans in answer number 4. Unfortunately, the lines were wrapped incorrectly and that's confusing. Here is the correct code which works :

    Here's the code to force a ListBox to Scroll to a specific row. I put it behind a
    Command Button Named Customer, you can obviously do whatever you want. Really should
    be a Class Wrapper for a ListBox to expose a TopIndex property like VB ListBoxes.
    ' ***CODE START 
    'Place this code in the General Declarations of your Form:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ 
    (ByVal hWnd As Long, ByVal wMsg As Long, _ 
    ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function GetFocus Lib "user32" () As Long
    ' Windows Message Constant 
    Private Const WM_VSCROLL = &H115 ' Scroll Bar Commands
    Private Const SB_THUMBPOSITION = 4 ' Code end for General Declarations
    ' Code for Control's Click Event Private Sub Customer_Click()
    Dim hWndSB As Long 
    Dim lngRet As Long 
    Dim lngIndex As Long 
    Dim LngThumb As Long
    ' You will get lngIndex value from the user or whatever. 
    ' For now I'm just setting it to arbitrary Number 
    lngIndex = 45
    ' SetFocus to our listBox so that we can 
    ' get its hWnd
    hWndSB = GetFocus
    ' Set the window's ScrollBar position 
    LngThumb = MakeDWord(SB_THUMBPOSITION, CInt(LngIndex)) 
    lngRet = SendMessage(hWndSB, WM_VSCROLL, LngThumb, 0&)
    ' Here's the MakeDWord function from the MS KB 
    Function MakeDWord(loword As Integer, hiword As Integer) As Long 
    	MakeDWord = (hiword * &H10000) Or (loword And &HFFFF&) 
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts