Using mouse to scroll down a combo list

E

efandango

Is there any way I can have my mouse wheel scoll up and down the actual
contents of a list on of a combo box.

I don't mean the standard 'scroll the list' where the list just moves up and
down but stays fixed on the initial selection. Instead I want the mouse to
scroll through the different field contents highlighting as it goes until I
find the field record that I want to use. Then just leave the box, making the
last selected (highlighted) field content my chosen record. I have a finite
list of 16 records in each combo box, and at the moment, have the 'List Rows'
property set to 16.
 
E

efandango

Arvin,

Thanks for the reply. Yes. everything you said, I understand (already knew).
But what I want is some way of having the 'highlight bar' move up and down by
just using the mouse wheel and not having to move the mouse. There is a very
good reason for this. I have numerous list of 16 records per combo box, and
they all eventually have to be picked (it's a qiz thing). and after a while
it gets 'tiring' on the eyes moving the mouse around, wheras it would be
better if the hightlight bar just moved up or down.

I know this is not the 'standard' way combo boxes are supposed to work, but
it suits this application better if I can get the mouse wheel to do the work.
 
S

strive4peace

Hi Eric,

alt-{down arrow} will drop the list
press {down arrow} to move to the next choice
(once you press {down arrow}, you can press {page up} and {page down})
then {tab} to exit the control and move to the next...

"16 records per combo box"

if you have room on the screen, you can make ListRows a higher number

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
E

efandango

Thanks Crsytal,

I was aware of these features of the combo box. It is mainy this messing
around with arrow keys to go up and down the list of entries that has led me
to want to do the same woth the mouse wheel. The 16 records per combo are
finite; so no need to increase ListRows. I just want the user to be able to
not have to leave the mouse/wheel. The combo box appears on every 'page#' of
the main records. It's a quiz answer list, and all 16 have to be answered,
hence the desire to just have the mouse wheel scroll the 'highlight' bar up
and down. (and it would look as neat as it would be to actually use.)

regards

Eric
 
S

strive4peace

Hi Eric,

rather than making the user choose each question, add the questions for
them.

I will assume you have a table where the questions are defined

Questions
- QID, autonumber
- Question, text
etc

and tables with test info and where you record answers

Tests
- TestID, autonumber
- PersonID, long -- FK to identify who is taking the test
- TestDate, date

Answers
- AID, autonumber
- TestID, long -- FK to tests
- QID, long -- FK to Answers

in the Answers table, make a multi-filed unique index on the combination of
TestID
QID
(instructions on how to do this are in Access Basics) -- this is so, if
you accidentally append questions twice, you do not end up with duplicates

then, when you make a new record for Tests, on the form AfterUpdate
event, append all the questions to the answers table and requery the subform

'~~~~~~~~~
dim strSQL as string
strSQL = "INSERT INTO Answers (TestID, QID) " _
& " SELECT QID, " & me.testid _
& " FROM Questions;"
currentdb.execute strSQL
currentdb.tabledefs.refresh
DoEvents

me.subform_controlname.requery
'~~~~~~~~~~~~~~

hopefully, you can see the logic of this. If not, post back with
questions <smile>


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
E

efandango

Crystal,

I appreciate your advice on the structure of a question and answer setup;
but I already have all that working just fine. I just wanted to improve the
interface/ergonomics aspect of the user experience. In saying that I already
have a complete setup working well; there is always somethine one can learn.
In time I will look at your structure setup more closely and see if I can use
it to improve my working solution. In the meantime; is there a definitive
answer as to whether I can have my mousewheel scroll the highlight bar up and
down, rather than have the laist itself move up and down (which incidently,
it doesn't due to the max 16 items which I can easily accomodate on my form)

regards

Eric
 
S

strive4peace

Hi Eric,

"advice on the structure"

you know me too well ;)

actually, this wasn't about structure -- just used the structure example
to show you how to automatically create the answer records and eliminate
the need for the users to do it ;)


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
E

efandango

Hi Crystal,

LOL... :)

after our exchanges on my 'How can I Automate a complex update process
involving 3-4 tables?.' thread; I feel I know you quite well. Nice to know
you are back in the groove after your recent holiday/trip. I will come back
to you on the outstanding question above if I may, just as soon as I have
recharged my batteries and tightened things up with the database.

Meanwhile...

is there a definitive answer as to whether I can have my mousewheel scroll
the highlight bar up and down, rather than have the laist itself move up and
down (which incidently, it doesn't due to the max 16 items which I can easily
accomodate on my form) can it be done with some kind of control code? or does
a non-reply to this question imply that the answer is a resounding, No?...


best regards

Eric
 
S

strive4peace

Hi Eric,

<smile>

I did not respond to the 'mousewheel' part of your question because I
have no experience with it. You might want to check Stephen Lebans site
-- here is a link for something on the mousewheel -- not what you are
asking but it may give you some ideas:

Mouse Wheel On/Off, by Stephan Lebans
http://www.lebans.com/mousewheelonoff.htm

another good site to search (I just did and it turned up several links
for 'mouse wheel') is:

http://MVPs.org/



Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
S

Stephen Lebans

If you are using a recent version of Access then the MouseWheel Event is
available to you. Within this event you would call your code to manipulate
the List/Combo control. Here are three different methods. From my Web site
here:
http://www.lebans.com/List_Combo.htm


Here is an example containing code behind two CommandButtons to scroll
through the List portion of the control.
If you'd like to use the Arrow Keys to navigate through a ListBox even if
the ListBox does not have the focus then read on.

Go to Form properties and set the Key Preview to Yes.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyDown
Me.List2 = Me.List2.ItemData(Me.List2.ListIndex + 1)
KeyCode = 0


Case vbKeyUp
Me.List2 = Me.List2.ItemData(Me.List2.ListIndex - 1)
KeyCode = 0

Case Else
End Select

End Sub

Tthe above code is for a ListBox named List2. Change the name to reflect
your ListBox. Also this is set to work with a ListBox WITHOUT Column Headers
turned on. You'll have to adjust it if you use Column Headers. Finally the
Arrow Keys are sent to oblivion with the Line KeyCode =0.




Scroll a ListBox to a specific row. Emulates the VB ListBox TopIndex
property. You can alter the code to easily have the selected row display as
the first or last row as well. The example code is placed behind a Command
Button.

' *** CODE START
Private Sub cmdListIndex_Click()
On Error GoTo Err_cmdListIndex_Click

' Always make NumRows an odd number
' if you want selected Row to be in the
' middle of the ListBox.

' NumRows is the number of completely visible rows in the ListBox Const
NumRows = 7
' Row we want displayed in middle of ListBox.
Dim intDesiredRow As Integer

' Arbitrarily select the 24th row.
intDesiredRow = 24
' ListBox must have the Focus
Me.List2.SetFocus
' Force ListBox to start from the top
Me.List2.ListIndex = 1

' Force the Scroll offset we desire
Me.List2.ListIndex = intDesiredRow + (NumRows / 2)
' Now select the row without further scrolling
Me.List2.ListIndex = intDesiredRow

Exit_cmdListIndex_Click:
Exit Sub

Err_cmdListIndex_Click:
MsgBox Err.Description
Resume Exit_cmdListIndex_Click

End Sub
' ***CODE END


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








Your mileage may vary. :)




--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
E

efandango

Stepehen,

That's great News!

Thanks so much for your concise reply. I will now go and try your code.

regards

Eric
 
E

efandango

Stephen,

I noticed that your code seems to just refer to ListBox's; can it work with
ComboBox lists as well?

regards

Eric
 
E

efandango

Hello Stepehen,

I have looked at your sample mdb, but cannot see the listbox working the way
I was hoping that it would. eg: move the mouse wheel and the list item
highlight bar moves through the list. You also mentioned the MouseWheel
event, but I cannot see any reference to it or how to utilise it in the help
files. I am Using MS Access 2007.

Your samples all make reference to using command buttons; I am guessing that
I would have to switch the command buttons reference to the mousewheel event
options. yes?. Also, my combo box is using a table/query for its RowSource,
albeit with a permanatly fixed no of (16) records each time.

regards

Eric
 
S

Stephen Lebans

I still do not have A2007 installed here. The MouseWHeel event is a form
level Event not a control event.
And yes, as I stated, you would have to copy the logic/code form my sample
to the MouseWheel event.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top