Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423

    I just stumbled on some code when I went to remove a message box for an opening form. It seems you can set event properties in one go. This happens to be in the Load event for the form, probably because you can't set these properties unless the form is in design view. You could put it in design view using a version of this and run it once and it should stick.
    Code:
        Dim L As clsLabel
        Dim c As Control
        'Keep an instance of the clsLabel for each label in the form.
        Set mcolLabels = New Collection
        For Each c In Me.Controls
            If TypeName(c) = "Label" Then
                c.OnClick = "[Event Procedure]"
                c.OnMouseDown = "[Event Procedure]"
                c.ControlTipText = "Click on " & c.Name
                Set L = New clsLabel
                Set L.Target = c
                mcolLabels.Add L, c.Name
            End If
        Next c
    This is in the form module declaration section
    Private mcolLabels As Collection
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  2. #17
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Here's an example which may do what you want.
    The display form has 56 image controls so it can handle up to 56 images in a folder.
    It uses a collection and a couple classes.
    The classes handle the controls and click events
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #18
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,931
    how to pass the control name to the MouseDownEvent function
    screen.activecontrol should give it to you since the gotfocus event occurs before mousedown. But from your code, it looks like you have image controls - image controls (like labels and some other controls, check for the gotfocus event) cannot receive the focus which is probably why your code wasn't working as expected

    Another option is to use the undocumented acchittest function which returns the name of the control below the cursor.

    see this link and find this code

    https://www.isladogs.co.uk/control-p...ode/index.html


    Code:
    Dim pt As POINTAPI
    Code:
    Dim accObject As Object
         GetCursorPos pt
         Set accObject = frm.AccHitTest(pt.X, pt.Y)
         If Not accObject Is Nothing Then GetControlName = accObject.Name
    


    GetCursorPos is an API you will need to add to your module

    frm you will need to pass as a parameter e.g.

    "=MouseDownEvent([FORM],1)"

    Function
    MouseDownEvent(frm as form, pintImage As Integer)



  4. #19
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by orange View Post
    ChrisO, a former participant in many forums (now deceased), provided info on class modules and event handlers.
    See this post and others by ChrisO in that thread for more info.
    I haven't looked at the thread but many of ChrisO's samples are here:

    https://www.baldyweb.com/ChrisOSamples.htm

    The one that does what might be useful here is the drag and drop sample. I adapted it to an app years ago and it worked like a champ.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #20
    Miles R is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Quote Originally Posted by Micron View Post
    .Tag was just an example of a parameter that I thought might be useful since you could edit a tag and maybe not have to edit code. You could pass a simple string or number instead. Yes, you would have to edit every function call for every control you need this for, but at least you'd only have one function to write. As I mentioned, pretty sure there are posts in here somewhere that contain db attachments that use a class for this.

    Yes I saw about the left/right buttons, which is why I said I wouldn't bother to try and pass the button - just code for the button. If you need the button value, why not just get it from the mouse event since it's already 'created' that value for you?
    Not sure what you mean by that as the DLL to get the right or left mouse click does not know anything about which of the 55 controls on my form was pressed. There is only one Event Function with parameter, not an Event Procedure for each control.

    However, I now have another solution. I have written a few lines of code that opens the Form in design mode, sets all the 55 On Mouse Down events to point to my single function, with a single parameter of the control number. Crude but effective and I only have to run this once. Saves me editing all the controls manually.

  6. #21
    Miles R is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Thanks for all the replies. I did not see some as I had forgotten to look at page 2.
    Some of the posts and replies have crossed in the post as it were.
    As you will see, I have found a simple solution similar to what Micron suggested, but my code is just in a Module, called from a Macro.

    Yes, the controls are images, which as CJ_London suggested is probably why the focus is not set to the image.

    Anyway, don't need to do any more on this now as I have solved the Mouse Click problem and crudely set the On Mouse Down events each with their own parameter, all in one go.

    I have marked this thread as solved.

    Thanks for all the help.

  7. #22
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    I used these classes


    Class name: CSingleButton
    Code:
    Public buttonsHandler As CButtons
    Public WithEvents btn As Access.Image
    
    
    Private Sub btn_Click()
        buttonsHandler.HandleClick btn
    End Sub

    Class name: CButtons
    Code:
    Private ButtonHandlers As Collection
    Dim Tbx As Access.TextBox
    Const MODE_DEBUG As Boolean = True
    
    
    Public Sub LoadButtons(ByRef TheForm As Access.Form, Target As Access.TextBox)
    
    
        Dim ctl As Control
        Dim btnHandler As CSingleButton
        Set ButtonHandlers = New Collection
        For Each ctl In TheForm.Controls
            If ctl.ControlType = acImage Then
                Set btnHandler = New CSingleButton
                Set btnHandler.btn = ctl
                Set btnHandler.buttonsHandler = Me
                ctl.OnClick = "[Event Procedure]"
                ButtonHandlers.Add btnHandler
            End If
        Next ctl
        
        Set Tbx = Target
    
    
    End Sub
    
    
    Public Sub HandleClick(btn As Access.Image)
    
    
        'If MODE_DEBUG Then Debug.Print btn.Name & "_Click" & btn.Tag
        'Debug.Print btn.Tag & "*"
      
        Tbx = btn.Tag
      
        DoCmd.Close acForm, btn.Parent.Name
      
    End Sub
    One disturbing thing I came across:
    Click image for larger version. 

Name:	Screenshot 2025-01-09 131547.png 
Views:	21 
Size:	21.3 KB 
ID:	52556
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  8. #23
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    DLL to get the right or left mouse click does not know anything about which of the 55 controls on my form was pressed
    I took your comments around the button issue to mean you wanted to know which button, not which control...
    Code:
    but need to know whether it was left or right mouse click.
    Anyway, glad to see that you have a solution and thanks for the rep points.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 03-11-2015, 12:48 PM
  2. Replies: 1
    Last Post: 12-17-2014, 11:53 AM
  3. External script to call Command Button Click event handler
    By Sean Nakasone in forum Programming
    Replies: 5
    Last Post: 10-29-2014, 12:35 PM
  4. Replies: 4
    Last Post: 02-14-2013, 10:06 AM
  5. Replies: 3
    Last Post: 05-07-2012, 12:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums