• Scroll Mouse Problem Fixed?? (access 97)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Scroll Mouse Problem Fixed?? (access 97)

    Author
    Topic
    #368474

    i have looked everywhere to fix the problem of the scroll mouse scrolling through records on a form. here is what i found. i can’t get it to work as of yet (some of the code lines come up red) could someone please look over the code to see how to get it to work? it is supposed to disable the scroll button on each form.

    This is added to a Module:

    Declare Function CallWindowProc Lib “user32” Alias _
    “CallWindowProcA” (ByVal lpPrevWndFunc As Long, _
    ByVal hwnd As Long, ByVal Msg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long

    Declare Function SetWindowLong Lib “user32” Alias _
    “SetWindowLongA” (ByVal hwnd As Long, _
    ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

    Public Declare Function RegisterWindowMessage& Lib “user32” Alias “RegisterWindowMessageA” _
    (ByVal lpString As String)

    Public Const GWL_WNDPROC = -4
    Public IsHooked As Boolean
    Public lpPrevWndProc As Long
    Public gHW As Long

    Public Sub Hook()

    If IsHooked Then
    ‘MsgBox “Don’t hook it twice without ” & _
    ‘ “unhooking, or you will be unable to unhook it.”
    IsHooked = True
    Else
    lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
    AddressOf WindowProc)
    IsHooked = True
    End If

    End Sub

    Public Sub Unhook()

    Dim temp As Long
    temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    IsHooked = False

    End Sub

    Function WindowProc(ByVal hw As Long, ByVal uMsg As _
    Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    If uMsg = GetMouseWheelMsg Then
    ‘ Debug.Print “Message: “; hw, uMsg, wParam, lParam
    WindowProc = 0
    Else
    WindowProc = CallWindowProc(lpPrevWndProc, hw, _
    uMsg, wParam, lParam)
    End If

    End Function

    Public Function GetMouseWheelMsg() As Long

    GetMouseWheelMsg = 522 ‘this works for Win98/2000, otherwise use
    ‘RegisterWindowMessage(“MSWHEEL_ROLLMSG”)

    End Function

    This is added to each Form:

    Sub Form_Load()

    ‘Store handle to this form’s window
    gHW = Me.hwnd

    If IsHooked Then
    Call Unhook
    End If

    ‘Call procedure to begin capturing messages for this window
    Call Hook

    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    ‘Call procedure to stop intercepting the messages for this window
    Call Unhook
    End Sub

    Viewing 1 reply thread
    Author
    Replies
    • #577490

      Mine comes up red line on:
      lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
      AddressOf WindowProc)

      If someone can help out here, this will be outstanding if it really does stop the mouse scroll.

      Where’d ya get the code from? Maybe the author could help us out?
      crossfingers

      Michael

      • #577492

        that’s where mine stops too. there is also one more place it stops, but i don’t remember where.

        of course, i got this from someone who got it from someone who found it somewhere etc….

        anyway, i’m sure someone like charlotte could find the problem…. (let’s see if she takes up the challenge! – i know you want to charlotte! ) grin

        • #577495

          Have you tried taking the cursor to the end of the first red line

          lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, (delete the underscore and press delete)

          This should bring the next line up and continue the statement.

          P.S where do you put this code and how do you make it work.

          • #577502

            Dave – Yes I already tried that. No go.
            I put the code in a new module and cut the parts out for the Form Load & Unload and pasted it into the forms module.

            If I am reading it correctly, it calls the function when the form loads and “undoes it” when unloading the form.

            So Rory, I guess WIN2000 + Acc97 won’t cut it with this code?

            Hopefully someone, someday can modify it for A97.

            Thanks fellas.

            Michael

            • #577505

              Sadly, no. It has to be Office2k or above. There might I suppose be an API call to do the equivalent of the AddressOf operator – I’ll see if I can find anything when I have some free time.

    • #577494

      Hi,
      I don’t believe you can use this in versions of Office prior to 2000 as it involves a callback function. The AddressOf operator passes the address of a VBA function to the dll and is new to VBA6.

      • #577497

        now rory, i’m just going to have to disregard that last post…. it is entirely not what i wanted to hear evilgrin. anyway, does this mean that it would work with access 2000? is there any way around this for 97? grasping at straws here – this is one of the biggest unsolved problems that i have seen. thanks for your input

        • #577500

          I haven’t tested it (don’t have a scroll mouse at home) but the code certainly compiles quite happily. To the best of my knowledge there is no way of using a callback function in 97 or prior, but that’s not to say that there isn’t a workaround for this particular problem.
          Happy hunting….

          • #577626

            Access 97 handled callbacks. I haven’t messed with this code to see what it actually does in 97, and I don’t have time to for at least a few days. So have fun, guys! grin

            PS/ Access 97 doesn’t handle AddressOf, as Rory pointed out, so I doubt you can make this work.

        • #577665

          Good news, possibly. It is apparently possible to recreate the functionality of the AddressOf operator in Access 97. There’s an article on the Access Web referring to another site with the code. You will however have to subscribe in order to view the code and there appear to be a number of warnings along with it!
          Hope that helps.

        • #577680

          This zip file from the Trigeminal website contains a spreadsheet with an AddrOf function in it which allegedly works in Office 97. You can see from the comments in the code that it was fun to work out!
          You will need to replace the
          AddressOf procname
          in the module you’ve got with:
          AddrOf(“procname“)
          and then hopefully it should work. I’d strongly recommend backing up your database first as this is not supported by MS in any way.
          Hope that helps.

          • #577684

            wow, this is getting deep….
            it is now giving an “argument not optional” for addrof(windowproc) and it is highlighting “windowproc”. this is getting a bit over my head. it would be greatly appreciated by all if you could test it out to see if you can get it to work. thanks for your help so far!

            • #577690

              It should read
              AddrOf(“windowproc”)
              rather than
              AddrOf(windowproc)
              Does that help?
              I can’t test it as I don’t have Access97.

            • #577691

              well…

              as it sits, it stops and gives the error “Sub or function not defined” at “addrof”, so i added the code:

              Public Function AddrOf(WindowProc) As Long

              End Function

              which satisfied the error, but ended up making all the code apparently do nothing. i found that bit of code in the spreadsheet you told me to look at. perhaps i coded it incorrectly or there probably needs to be some code in that fuction, but heaven knows i have no idea what that code may be. make any sense? scratch

            • #577693

              You may be interested in looking up
              SystemParametersInfo

              specifically SPI_GETWHEELSCROLLLINES / SPI_SETWHEELSCROLLLINES

              follwed by WM_SETTINGCHANGE

              This isn’t ideal as it will apply to all programs using the system, not just your app.

            • #577724

              Hi,
              I’d suggest removing that function – as you know it doesn’t actually do anything. Then add a new module and paste this into it (I’ve included all the comments as it’s not mine!):

              '--------------------------------------------------------------------------
              '   Declarations
              '
              '   These function names were puzzled out by using DUMPBIN /exports
              '   with VBA332.DLL and then puzzling out parameter names and types
              '   through a lot of trial and error and over 100 IPFs in MSACCESS.EXE
              '   and VBA332.DLL.
              '
              '   These parameters may not be named properly but seem to be correct in
              '   light of the function names and what each parameter does.
              '
              '   EbGetExecutingProj: Gives you a handle to the current VBA project
              '   TipGetFunctionId: Gives you a function ID given a function name
              '   TipGetLpfnOfFunctionId: Gives you a pointer a function given its function ID
              '
              '--------------------------------------------------------------------------
              Private Declare Function GetCurrentVbaProject _
               Lib "vba332.dll" Alias "EbGetExecutingProj" _
               (hProject As Long) As Long
              Private Declare Function GetFuncID _
               Lib "vba332.dll" Alias "TipGetFunctionId" _
               (ByVal hProject As Long, ByVal strFunctionName As String, _
               ByRef strFunctionId As String) As Long
              Private Declare Function GetAddr _
               Lib "vba332.dll" Alias "TipGetLpfnOfFunctionId" _
               (ByVal hProject As Long, ByVal strFunctionId As String, _
               ByRef lpfn As Long) As Long
              
              '--------------------------------------------------------------------------
              '   AddrOf
              '
              '   Returns a function pointer of a VBA public function given its name. This function
              '   gives similar functionality to VBA as VB5 has with the AddressOf param type.
              '
              '   NOTE: This function only seems to work if the proc you are trying to get a pointer
              '       to is in the current project. This makes sense, since we are using a function
              '       named EbGetExecutingProj.
              '--------------------------------------------------------------------------
              Public Function AddrOf(strFuncName As String) As Long
                  Dim hProject As Long
                  Dim lngResult As Long
                  Dim strID As String
                  Dim lpfn As Long
                  Dim strFuncNameUnicode As String
                  
                  Const NO_ERROR = 0
                  
                  ' The function name must be in Unicode, so convert it.
                  strFuncNameUnicode = StrConv(strFuncName, vbUnicode)
                  
                  ' Get the current VBA project
                  ' The results of GetCurrentVBAProject seemed inconsistent, in our tests,
                  ' so now we just check the project handle when the function returns.
                  Call GetCurrentVbaProject(hProject)
                  
                  ' Make sure we got a project handle... we always should, but you never know!
                  If hProject  0 Then
                      ' Get the VBA function ID (whatever that is!)
                      lngResult = GetFuncID( _
                       hProject, strFuncNameUnicode, strID)
                      
                      ' We have to check this because we GPF if we try to get a function pointer
                      ' of a non-existent function.
                      If lngResult = NO_ERROR Then
                          ' Get the function pointer.
                          lngResult = GetAddr(hProject, strID, lpfn)
                          
                          If lngResult = NO_ERROR Then
                              AddrOf = lpfn
                          End If
                      End If
                  End If
              End Function
              

              Do a debug and compile to make sure that’s all OK and then hopefully you’re away!

            • #577743

              rory, Rory, RORY!!!!! by jove, i think we’ve got it!! clapping on my first test, it disabled the scroll wheel (and only on the current form – all other forms and applications were unaffected!!!) when the form was unloaded, it enabled the scroll again. i think this might be one of the biggest discoveries yet!! got to tell everyone now!!

              thanks for all your help rory! bow bravo cheers clapping clever fanfare grin groovin joy king thumbup

            • #577756

              One minor caveat (I know, I know, you don’t want to hear this!) – I tested your original code in A2K and some very strange things happened to my system. It was fine until I moved the mouse pointer over the form at which point everything froze. This may be down to the fact that I’ve got 2 scroll mice connected to my PC (Win2K) or the fact that one is an Optical Trackball, or to some bizarre combination of factors specific to my PC, but I thought I’d warn you so you can at least test a few configurations before rolling it out to anyone.
              Still, at least it works for you! grin

            • #577776

              Sorry if I am butting in here, but I have been following this thread since yesterday, building a Test db for this.
              I cannot find where my error is, but when I open the form it comes up with the message : “ms access has generated errors etc.”
              Would either of you be kind enough to look at the code in the module and the form and let me know what I have done wrong?
              (I am on WIN2000-A97)
              I really appreciate it fellas.

              Michael
              (edited for spelling)

            • #577781

              Did you use Access Security when you created this db? I can’t open it or convert it.

            • #577787

              Sorry ’bout that.
              I have replaced it unsecured.

              Thanks!!!

            • #577825

              Well, I copied and pasted AccesssMan’s code verbatim – VOILA !! Out-freakin’-standing !!!!

              Thank you all SO much.

              I hope someday I can return the favor(s).

              Unbelievable!!!

              Michael Abrams

            • #577850

              Ditto. that is a marvelous piece of work. I don’t know how many times I’ve accidentally hit the scroll wheel on a form and launched it into never-never land. You’ve solved a huge puzzle.

              Thanks very much to AccessMan and Rory!!!

            • #616955

              PLEEEZE could someone send up a zip file with this code working on a form. I have tried to follow the solution but I get error city.

            • #617032

              [indent]


              PLEEEZE could someone send up a zip file with this code working on a form.


              [/indent] It’s against Rule 10 to ask like this. However, you can download the attachments from the prior posts if you want examples.

    Viewing 1 reply thread
    Reply To: Scroll Mouse Problem Fixed?? (access 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: