How to call a module in main code VBA

murray83

Games Collector
Local time
Today, 19:58
Joined
Mar 31, 2017
Messages
762
So i have this code which works fine when its in the main VBA section

Code:
'---------------------------------------------------------------------------------------
' Purpose   : Use instead of hyperlink to change mouse cursor to pointing hand.
' Author    : "Mister Slimm"
' Source    : http://misterslimm.wordpress.com/2007/06/21/microsoft-access-2002-emulate-hyperlink-cursor-change/
' Adapted By: Mike Wolfe
' Reposted  : https://nolongerset.com/usehand/
' Usage     : Set OnMouseMove of control to =UseHand()
'---------------------------------------------------------------------------------------
Public Function UseHand()
    Const IDC_HAND As Long = 32649&
    
    ' Load new cursor and, if successful, set it
    Dim hLastCursor As Variant  'Long/LongPtr
    hLastCursor = LoadCursor(0, CLng(IDC_HAND))
    If (hLastCursor > 0) Then
        hLastCursor = SetCursor(hLastCursor)
    End If
End Function

But then when i put it into a Module and then put

Code:
Private Sub callhand()
Call UseHand
End Sub

I get access shouting at me saying as in the attached. have tried searching on line but cant make out what i may have done wrong

cheers all for looking
 

Attachments

  • What you want.PNG
    What you want.PNG
    881.2 KB · Views: 88
I think i might have seen the error of my ways

22:25 and no i didnt make it work, thought i had it.
 
A. Do you have the rest of that code from that link?
B. Why are you not using it as it is described?
 
Seens to me you are missing a bunch of declarations
 
Seens to me you are missing a bunch of declarations
You mean these

Code:
Option Compare Database
' UseHand() declarations - paste the #If - #End If lines at the top of the module
#If VBA7 Then
    Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" ( _
                                    ByVal hInstance As LongPtr, _
                                    ByVal lpCursorName As Long) As LongPtr
    Private Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As LongPtr) As LongPtr
#Else
    Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, _
                                    ByVal pCursorName As Long) As Long
    Private Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
#End If

i did add them to the module after i saw them on the form pages but it still wont let me call it from the module just has to be coded to each form
 
And how are you calling it from the mousemove event? Show the code if vba or screenshot of the property

also recommend you have option explicit at the top of every module
 
yeah im not sure how mine works as my code is a lot shorter then what they have listed on that url in the comments ill post an example in a second
 
It plainly says how to use it in the comments?
Why are you not even trying that way? :(
 
my shorter version is taking from here whcih is also mentioned in the comments and works fine when its In the explicit and main code but would just like to have it all nice and neat in a sub routine ( module ) whcih i can then just call

 
huge number of errors in the code (438, 3078, 'no object' in the control' to mention a few). Plus you have multiple public versions of the function and your module has the same name.

Change the name of the module to something like 'modUseHand' and comment out or remove all the UseHandsfunctions in the form

And use Option Explicit
 
You mean these

Code:
Option Compare Database
' UseHand() declarations - paste the #If - #End If lines at the top of the module
#If VBA7 Then
    Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" ( _
                                    ByVal hInstance As LongPtr, _
                                    ByVal lpCursorName As Long) As LongPtr
    Private Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As LongPtr) As LongPtr
#Else
    Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, _
                                    ByVal pCursorName As Long) As Long
    Private Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
#End If

i did add them to the module after i saw them on the form pages but it still wont let me call it from the module just has to be coded to each form
Not related with the error but the PtrSafe in the #Else should be deleted.
 

Users who are viewing this thread

Back
Top Bottom