Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Common Sub to test use of Ctrl key with Screen.ActiveControl

    If one has quite a number of text boxes on a form and essentially wants to take a single action whenever one of the text boxes gets a mouse down action together with the Ctrl key held down, is there a method where the Ctrl key can be tested without having to code a MouseDown event for every text box?

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You can assign a function to every textbox upon form open and within that syntax/expression, pass the control name along with it. Mousedown has 3 constants for shift, control and alt keys. Your called function could detect which of those keys, if any, were held down at the time. The only time I play with this sort of thing is when helping out. In fact, I think this line (assigning an event to all unattached labels) is from helping you out with your labels, so maybe you already know that you don't have to code for every type of a control on a form?

    Me.Last_Name_Label.OnClick = "=GetCtlName(""" & Me.Last_Name.Name & """)"

    EDIT - in fact, code for a class was provided, meaning you were given 2 approaches to not having to write a function for every control?
    Sorry if I'm missing the point. However, I confess that I haven't tried to assign any mouse events in the suggested manner so maybe it's not possible to detect the shift property value when using that approach.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    it's not possible to detect the shift property value when using that approach.
    That's what led me to the OP. I couldn't figure out how to test "Shift" unless I was in a MouseDown event code.

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I'd have to review the class code thread to see how the class worked with (or substituted for) any particular event. I suppose it's not as simple as changing
    C.OnClick = "[Event Procedure]"
    to
    C.OnMouseDown = "[Event Procedure]"

    Nevertheless, I'm intrigued, but perhaps accesstos will chime in with a solution that uses that class.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I too was intrigued at the outset of the challenge, as to how to have a single Sub where I could test the Shift property in a procedure other than the MouseDown event on a per control basis.

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    After about an hour of playing with the class I have to admit defeat - at least for the time being. While the class seems to react to the click event
    Code:
    Private Sub mTarget_Click()
        'You may code this proc as you need.
        MsgBox Me.Target.Caption, , Me.Target.Name
    End Sub
    it does not seem to react to MouseDown, even with no breakpoints on it
    Code:
    Private Sub mTarget_OnMouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
       MsgBox Me.Target.Name
    End Sub
    EDIT -good grief, between this and another thread I've been looking at code for hours. I'm at the point where I'm not concentrating, rather, details are crossing over to where they should not. This works

    Code:
    Private Sub mTarget_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
       MsgBox Me.Target.Name & " Shift: " & Shift
    End Sub
    I had OnMouseDown in 2 places, one which was wrong. So it seems I've figured it out. As indicated (?) add
    .OnMouseDown = "[Event Procedure]"

    to the class event(s) list and the above procedure to the class where you have/had the click event already.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by Micron View Post
    I'd have to review the class code thread to see how the class worked with (or substituted for) any particular event.
    Do you refer to this thread?

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Off to a boatload of appointments this morning, I'll try to assimilate all of this later today.

  9. #9
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    No, this one https://www.accessforums.net/showthread.php?t=84608

    As noted, I got the MouseDown code to run by adding to your class code and showed the Shift value in a message box. Interesting set of values for Shift parameter value. Something like
    no button = 0
    shift = 1
    ctrl = 2
    shift+ctrl = 3
    alt = 4
    shift+alt =5
    shift+alt+ctrl = 7
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    As noted, I got the MouseDown code to run by adding to your class code and showed the Shift value in a message box
    I'm not at all familiar with the creation of a new class, would you post your modification of @accesstos code? Also, not sure exactly what you mean to add as the property of the OnMouseDown event.

  11. #11
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Note that the class code didn't contain the line in red:
    Code:
    Property Set Target(lbl As Access.Label)
        Set mTarget = lbl
        If Not mTarget Is Nothing Then
       With mTarget
         .OnClick = "[Event Procedure]"
         .OnMouseMove = "[Event Procedure]"
         .OnMouseDown = "[Event Procedure]"
         'mlngColor = .BorderColor
         'mintClicks = 1
       End With
            'UpdateTipText
        End If
    
    End Property
    You might recall the comment (green) from the code in that thread, which contained the call/reference to the click event. All I did in addition to the red above is to add the event property (?) [blue] to that code in the clsLabe module:

    Code:
    Private Sub mTarget_Click()
        'You may code this proc as you need.
        'MsgBox Me.Target.Caption, , Me.Target.Name
    End Sub
    
    Private Sub mTarget_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
       MsgBox Me.Target.Name & " Shift: " & Shift
    End Sub
    Last edited by Micron; 10-27-2021 at 06:28 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I don't seem to be able to get any reaction with MouseDown even.

    Here's the code in the class module:
    Code:
    Option Compare Database
    Option Explicit
    
    
    Public WithEvents Target As Access.Label
    
    
    Private Sub Target_Click()
    'You may code this proc as you need.
    MsgBox Me.Target.Caption, , Me.Target.Name
    End Sub
    
    
    Private Sub mTarget_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    MsgBox Me.Target.Name & " Shift: " & Shift
    End Sub
    And, here's the code in the form's OnLoad event:
    Code:
    Private Sub Form_Load()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    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
    
    
    On Error GoTo Err_Handler
    
    (Snip)
    I have both the OnClick and OnMouseDown properties of a label control set to "[Event Procedure]". I get the expected reaction to a click on the label, but nothing on a mouse down action?

    What am I missing?
    Last edited by GraeagleBill; 10-28-2021 at 01:25 PM.

  13. #13
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Found the problem. Didn't notice the "m" on the "Target".
    Attachment 46500

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by GraeagleBill View Post
    Found the problem. Didn't notice the "m" on the "Target".
    Attachment 46500
    Yes, they seem to use that prefix in classes for some reason?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by GraeagleBill View Post
    Found the problem. Didn't notice the "m" on the "Target".
    Attachment 46500
    Yes, they seem to use that prefix in classes for some reason?

    Your attachment does not work BTW ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Screen.ActiveControl.Name
    By GraeagleBill in forum Programming
    Replies: 23
    Last Post: 10-21-2021, 06:34 AM
  2. Best screen resultion for most common screen sizes
    By sjs94704 in forum Database Design
    Replies: 3
    Last Post: 05-26-2015, 06:12 AM
  3. DoCmd.GoToRecord , , acGoTo, Screen.ActiveControl
    By hnhpak in forum Programming
    Replies: 6
    Last Post: 04-14-2015, 07:13 AM
  4. Replies: 9
    Last Post: 09-16-2014, 03:56 PM
  5. Usage of Screen.Activeform.ActiveControl - syntax
    By dcdimon in forum Programming
    Replies: 6
    Last Post: 06-17-2014, 09:05 AM

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