Lebans Holdings 1999 Ltd.

 Home ] Up ] Feedback ] Contents ] Search ] What's New ] Files & Tips ] 

Select A Row
Home
Up
Select A Row
Magnify
LimitCharsMemo
RotateText
ImageClass
AutoSize TextBox
ZoomInOut
PaintProgram
FormatByCriteria
CmdButton
SetGetSB
Transparent
AnimatedGifPlayer
LoadJpegGif
ImageControlToClipBoard
CanGrow
LimitTextInput
AutoSizeFont
AnimateForm
AutoUpDown
MonthCalendar
AutoColumnWidth
RichText
SelectAlpha
FormDimensions
LoadSaveJpeg
TabColors
ToolTip
TextWidth-Height
MouseWheelOnOff
AlternateColorDetailSection
ConFormsCurControl
ConditionalFormatting
AutoSizeOLE
ChangeMDIBackGround
RecordNavigationButtons
HTMLEditor
CopyGetRTFfromClipboard
OpenForm
GradientFill

RETIRED! September 2009

I have officially retired from all things Access. Please do not send Email requesting support as I will not respond.

 

Keep all of your questions to the Newsgroups where everyone will benefit!

 

 

SetGetScrollBars.zip is a database containing functions to allow a user to programmatically set the position of a Form's Scrollbar in Continuous Forms or Datasheet view. 

NEW - Feb. 20/2000 Ver 1.0. SetGetScrollBars Replaces the older SelectARow functions for scrolling Forms. I have a new function for Scrolling List/Combo controls as well that I will post in the next week as well.

 

Nov 1999

If you do not need the full control available in SetGetScrollBars  but just need to Scroll your Form or SubForm, you can use the following code. 

it is straightforward to Scroll a Form's ScrollBars.
You can use the SendMessage function with the appropriate Windows Message. Remember to supply the correct hWnd property from the Form or SubForm you are trying to Scroll.
 
'****START CODE
'In the Form's General Declaration Section put:
Private Const WM_HSCROLL = &H114
Private Const WM_VSCROLL = &H115
' Scroll Bar Commands
Private Const SB_LINEUP = 0
Private Const SB_LINELEFT = 0
Private Const SB_LINEDOWN = 1
Private Const SB_LINERIGHT = 1
Private Const SB_PAGEUP = 2
Private Const SB_PAGELEFT = 2
Private Const SB_PAGEDOWN = 3
Private Const SB_PAGERIGHT = 3
Private Const SB_THUMBPOSITION = 4
Private Const SB_THUMBTRACK = 5
Private Const SB_TOP = 6
Private Const SB_LEFT = 6
Private Const SB_BOTTOM = 7
Private Const SB_RIGHT = 7
Private Const SB_ENDSCROLL = 8
 
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
 
 
' Here's some code to be placed in a Control's CLick event.
 
Private Sub Label16_Click()
Dim lngRet As Long
lngRet = SendMessage(Me.hWnd, WM_VSCROLL, SB_PAGEDOWN, 0&)
End Sub
'****END CODE
 

 

*********************************************

SelectARow.zip is a database containing 2 Functions with Source Code.
1)    Function to allow you to specify where the Selected Row of a List or Combo Box will appear in the display box.

2)   Function to allow you to specify where the Selected Row in a Continuous Form will be displayed.

ListBox

I ran into this problem several months ago. The standard Access ListBox control does not expose a property allowing you to specify what row is the first displayed row in the ListBox. Well, we have to do it the hard way.  I have successfully used 2 different methods.

A) API SendMessage with a VSCROLL Message to simulate the user manually changing position with the ScrollBars.

Place the following code behind the Click event of a Command Button. You'll just need to calculate how many pages and lines to scroll down based on the height of your ListBox and the row you need to select.
 
'****CODE START
Option Compare Database
Option Explicit


Private Const WM_HSCROLL = &H114
Private Const WM_VSCROLL = &H115
' Scroll Bar Commands
Private Const SB_LINEUP = 0
Private Const SB_LINELEFT = 0
Private Const SB_LINEDOWN = 1
Private Const SB_LINERIGHT = 1
Private Const SB_PAGEUP = 2
Private Const SB_PAGELEFT = 2
Private Const SB_PAGEDOWN = 3
Private Const SB_PAGERIGHT = 3
Private Const SB_THUMBPOSITION = 4
Private Const SB_THUMBTRACK = 5
Private Const SB_TOP = 6
Private Const SB_LEFT = 6
Private Const SB_BOTTOM = 7
Private Const SB_RIGHT = 7
Private Const SB_ENDSCROLL = 8


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

'So I used the 15th row in the the zero based index for this example. The ListBox is named List4.

'I have scrolled down 1 page in the ListBox

Private Sub Command1_Click()
Dim lngReturn As Long
Dim ListHwnd As Long


Me.List4.SetFocus
ListHwnd = GetFocus
Me.List4.Selected(15) = True

lngReturn = SendMessage(ListHwnd, WM_VSCROLL, SB_PAGEDOWN, 0&)
End Sub

'***CODE END

 

B) Let's Jump through some hoops! :-) This will allow us to specify exactly where we want a specific row to appear in the List Box. The logic here is to Select the row you want displayed in the usual manner, directly with a value as in List Box = CustomerId or with one of the Index properties, like List Box = ListBox.ItemData(0). You can then apply the following function to  resize the List Box so that the row you selected is displayed in the specified position.

Here's how to make a ListBox scroll to or
display the row you've selected in first row of the entire box.
Once you understand the logic you can easily apply it to your ListBox of whatever size it is.
 
 
Dim intTemp As Integer
 
intTemp = Me!ListBox.Height
Me!ListBox.Height = 800
'3500 centers the selected row!
Me!ListBox.Requery
Me!ListBox.Height = intTemp
 
Obviously sub the name of your Listbox for Me!Listbox.
 
The above works for a listbox with a height of 5940 twips. There is a header row and a horizontal scroll bar at the bottom of the box. This yields 27 displayable rows. I initially thought that the height I reset it to should be either 1 row or else 1/2 of the total ListBox's height. In the end 3500 twips is what works for me.
 

Form/ SubForm  Select where a Specific Row is Displayed

Generally, this question pops up in relation to data entry in a Form/SubForm. When a record is added/deleted or saved a Requery is often issued. After a requery  the recordset defaults to showing the first record at the top of the Form. If the user was say working on the 150th record, it is disconcerting to say the least to have to scroll back to the record they were working on prior to the requery.

There's a couple of different ways to handle this. Here's a few I've used.
 
1) Before you Update the Main Form (which causes the requery on the SubForm), save the Primary key for the Form and the SubForm's current row. After the Requery simply FindFirst for the Form, then select the stored row in the SubForm. 
 
2) If you are only Updating, not adding/deleting to the SubForm's recordset, then you can store the SelTop property prior to the Update and restore the SelTop property after the Requery.

3) Use the SendMessage API with VSCROLL messages to force SubForm to scroll back to the required position.

OK, for most situations, one of the above 3 methods will work fine. Still,  you'll notice that the  row we've selected appears as the top row displayed in the Form. Again this can be disconcerting to the user if the record they were working on prior to the Requery was at say the bottom of the screen. In order to restore the  displayed order of the rows after a Requery requires jumping through a lot of hoops. I don't personally feel it is worth it but that's up to you. There is a sample database in this archive detailing what hoops to jump through. Have fun!

I haven't updated this file in a while. I have recently had better success, with a lot less hassle, using SelTop and SendMessage  with VSCROLL together. I'll try to find time to update this in the future. :-) 

 

 
 

May 23, 2004 Product Update
 
 
Rich Text ActiveX control. Version 1.8

Click Here!

 

Mar 15, 2005 Product Update
 
MouseHook  Replaces the MouseWheel DLL subclassing solution. Turns On/Off the MouseWheel with one line of code. No DLL registration required. Now supports Logitech mice!

Click Here! 

 

 

 
Home ] Up ] Next ] 
Stephen Lebans Copyright 2009

Last Modified : 09/11/09 12:03 AM