|
Question : Access2003: working with mouse wheel
|
|
Hello experts, in my MS Access application is a form frm. On this form I want to use the mouse wheel using the following code: --- Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long) Dim tmpCurrentRecordNumber As Long Dim xCount As Long ' xCount = Count / 3 tmpCurrentRecordNumber = lngCurrentRecordNumber tmpCurrentRecordNumber = tmpCurrentRecordNumber + xCount If tmpCurrentRecordNumber < 1 Then tmpCurrentRecordNumber = 1 ElseIf tmpCurrentRecordNumber > lngCounterNumberOfRecords Then tmpCurrentRecordNumber = lngCounterNumberOfRecords End If lngCurrentRecordNumber = tmpCurrentRecordNumber Debug.Print "Wheel:" & CStr(Count) & " =+-records=" & CStr(xCount) ' End Sub --- One point in the code above is the const 3. I detected (by trial and error) that on my computer the "Scroll lines per scroll unit" also called "The number of lines at a time" has the value of 3. On other computers it is possible to modify this value in the mouse driver using the names above. My question is now, how is it possible to detect this value using vba code?
Can anyone give me some advices how to proceed? If possible please supply an appropriate snippet.
Thank you very much for any help
HStrix
|
|
Answer : Access2003: working with mouse wheel
|
|
HStrix,
Yep, sorry, I reread through that link, and I realized it makes references to classes that are not provided (the text is from a book, VBA Developers Handbook, and the classes were provided on a CD that, apparently, accompanied the book). The classes referenced handled setting up your API calls, and allowed you to access mouse properties by instancing a Mouse class. Obviously, without the class, you won't be able to do it.
But, no fear, here is the code that you need to accomplish what you want, and the steps involved in setting everything up. Do this:
1. In a new module (that I named GetMouseConfigInfo, but that you can name whatever you'd like), paste the following code:
Option Compare Database
Private Const SPI_GETWHEELSCROLLLINES As Integer = 104
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _ (ByVal uAction As Long, _ ByVal uParam As Long, _ lpvParam As Any, _ ByVal fuWinIni As Long) As Long Public Function GetScrollLines() As Long Dim GetWheelScrollLine As Long, lngValue As Long Call SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, _ lngValue, 0) GetScrollLines = lngValue End Function
2. On a form, create a command button. In the On_Click event of the new command button, paste the following code:
MsgBox GetScrollLines()
3. Save everything, and then view your form in Form View. 4. Click on the command button that you created. The number displayed in the message box will be the # of scroll lines that your mouse is configured to advance or retreat per mouse wheel tick.
You can adapt this code to store this value in a variable for use in your code. A note, I've never made calls to this API, so you may want to test this code out on a few machines on which you know the scroll lines/wheel tick value to test it out. I cannot do that here, or I would do it for you. I had to piece all this together from a couple of different sources, so not absolutely certain that this is returning the correct value, though, on my own 1 machine test, it seemed to.
And that's about it. Let me know if you have any questions.
Thanks,
Arek
|
|
|
|