Is it possible to subclass a report?

  • Thread starter Thread starter alex2005
  • Start date Start date
A

alex2005

Guest
Hi!

I want to make it possible for the user to click a button in a report but I understand that it's impossible. So im thinking, what if I can subclass a report and then use WM_LBUTTONDOWN, check the cursor position and take appropriate action if its over the button. However when I try to subclass the report access freezes and I have to restart it.. Can anyone tell me what im doing wrong? Im using Access 2002, and windows xp..

Here's the code im using..

----------------------------------- This code is in a module
Option Compare Database
Option Explicit

Public Const GWL_WNDPROC = -4

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

Public 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


Public Const WM_LBUTTONDOWN = &H201
Public Const GWL_WNDPROC = -4

Public lpPrevWndProc As Long

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

WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
End Function


--------------------------------------------
------------------------- This code is in a Report named "Report_Rapport1"

Private Sub Report_Open(Cancel As Integer)
lpPrevWndProc = SetWindowLong(Report_Rapport1.hwnd, GWL_WNDPROC, AddressOf WindowProc)

End Sub

Private Sub Report_Close()
Call SetWindowLong(Report_Rapport1.hwnd, GWL_WNDPROC, lpPrevWndProc)

End Sub

--------------------------------------------------------

This code shouldnt do anything as all messages is passed to the default window procedure right?
 
I'm assuming if you are going to such lengths to detect a button press on a report, you must have more than one button?

Is there any reason why you cannot use a customised toolbar rather than go to such exquisite methods?
 
Im sorry if i'm wasting you time here, but the reason im trying to do this is because of a bet I did with a friend of mine. Im only allowed to use access/vba so I guess I cannot use a systemwide hook to detect a button press.
 
Yeah.. I figured that out.. if It were a button then I could subclass it instead and that would be much more reliable.. But now I was thinking to subclass the report window, detect a click and then calculate if the mouse pointer is over the button(image) or I could check the colour under the mouse pointer.. But it doesnt seem like access want me to subclass the report.. Next step would be to use a timer and use some api's to see if the mousebutton is pressed down, but that is unreliable :(
 

Users who are viewing this thread

Back
Top Bottom