Oh...you're working with a ListBox not a Form's ScrollBar. Sorry about
that.One is a control and the other is not if I remember correctly.
Have you tried changing the code on my site to work with a Horizontal
Scrollbar?
Method #2
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
Me.List2.SetFocus
hWndSB = GetFocus
' Set the window's ScrollBar position
LngThumb = MakeDWord(SB_THUMBPOSITION, CInt(LngIndex))
lngRet = SendMessage(hWndSB, WM_VSCROLL, LngThumb, 0&)
End Sub
' 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 '***END CODE
--
HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Pachydermitis" <pr*******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Thanks Stephen,
I actually downloaded that and tried your methodology (slightly
modified of course) on my list box a couple days ago - to no avail.
Your solution is pretty slick. Thanks for making that available to
everyone.
Were you able to get a listbox to scroll horizontally?