Results 1 to 11 of 11
  1. #1
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94

    Blocking double click event on subforms

    Hi all,



    i have a number of forms with datasheet subforms that link to other forms when double clicking some fields. Now, due to the way I handle calls between forms (and other design choices) I'd like to lock those events depending how the form is called, so i disable the subforms on those cases to prevent double clicking. Which works alright, but I need the user to be able to select records for some button functionalities. So I've tried locking the form instead of disabling it, and also disabling the field with the double click event instead of the whole subform, but in both cases the double click event is still launching.

    Is there any way to prevent the double click event from triggering while still allowing users to select records on the subform?

    Thank you so much!

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    You can't stop an event from running code but you can look for some kind of condition in that event and act accordingly. One way would be to use the value you might be passing to OpenArgs when you open that form one way or another. Another might be a module level variable that you set when the form is open. As long as that form is open, the value of the variable is able to be read from other code. So you can wrap your current double click code in an IF block, and test for a condition that you create. F'rinstance, if said variable is True, then Exit Sub.

    EDIT - dblclick event also has a cancel feature, so probably could make use of that also.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    Gotcha, might try that approach if there's no quick way to lock or disable the field to prevent the event from triggering.

    Thanks, Micron.

  4. #4
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Just to clarify, I didn't mean you can't stop an event from taking place. Obviously if you disable a control its click event cannot occur. What I meant is that once the event takes place, you can't stop its code from executing. Also, if you disable a control, you might cause a different event to take place that you wouldn't expect, such as a click event on the form's detail section. Not saying you didn't understand that, just that I thought I wasn't clear enough for future readers.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    That's the thing, there's no other click event on the form or details section, just the double click on the particular field of the subform. Disabling the whole subform is preventing from launching the double click event, but disabling just the field (so that you can still select a record to interact with the buttons linked to the subform)
    Code:
    Forms("frm_usuarios").subfrm_puestos.Form.Puesto.Enabled=false
    isn't preventing the double click event from triggering. It greys out the field as if it was disabled but if I double click the field it still tries to open the new form. Thus my question asking if there's a way to prevent the user from triggering the double click event without disabling the whole form.

    When I've some spare time I'll try to handle it through open args and disable the field on the main form open event to see if that helps

    Edit:
    Passing an argument and disabling the field in the open event of the main form has the same behaviour. Field is greyed out but still allows the triggering of the double click event.

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    What I said was to test for the condition/parameter/module level variable value - whatever you use - and cancel or exit the sub. So if the case is "ignore double click if OpenArgs is 'read only' "

    Private Sub myControl_DblClick(Cancel As Integer)

    If Me.OpenArgs = "Read Only" Then Cancel = True (or you can exit sub)
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    Yep, I got that, Micron. That's my plan B. I was still trying to get it done by disabling the field because it shocks me that a disabled field still allows the click events of said field. One would assume that disabling the field would have the same effect as disabling the subform and block its related click events. Have had no success in getting it done that way though, regardless at what moment or from which event I disable the field, so it's time for plan B.

    Thank you very much

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I have seen this approach suggested.

    Code:
    Private Sub Command0_DblClick(Cancel As Integer)
       Cancel = True
    End Sub

  9. #9
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    I'm quite surprised also that a control on a subform will still respond to the event even when disabled.
    Simply disable the control as originally planned then:

    Code:
    Private Sub iEMAIL_DblClick(Cancel As Integer)
        If Me.iEMAIL.Enabled = False Then Exit Sub
        MsgBox "Hello"
    End Sub

  10. #10
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    The terminology and description in the OP might be a problem here. First, a form has no "lock" (or enabled) property so what is meant by
    So I've tried locking the form instead of disabling it,
    However, the sf control has these. If pressed, I probably would have said the event won't fire if a control was disabled, but I suppose it makes sense where f'rinstance, you want to enable it if you hold a certain user profile. I'm afraid that I don't see the point in the suggestions that basically exit an event regardless, because Lhoj says the event is sometimes needed to open other forms.
    I'd like to lock those events depending how the form is called,
    Now if we knew what condition(s) needs to be tested and what needs to happen as a result of each condition we could probably wrap this up quickly.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    So sorry for the late reply, as I stated some other time this is a side project on the very little spare time I have left as a support technician, which isn't much, so it has staid halted for some days.

    Quote Originally Posted by davegri View Post
    I'm quite surprised also that a control on a subform will still respond to the event even when disabled.
    Simply disable the control as originally planned then:

    Code:
    Private Sub iEMAIL_DblClick(Cancel As Integer)
        If Me.iEMAIL.Enabled = False Then Exit Sub
        MsgBox "Hello"
    End Sub
    I'm equally surprised. It would seem like a convenient and fast way to disable some events. Plus, it seems obvious that if you disable a field (not just lock it) you don't want the user interacting with it in any way, but OK.

    Your solution would have worked perfectly, so thank you very much. But since I can do the same checking the openargs of the main form I'll stick to it so I don't need to both disable the field and still control the event programmatically.


    Quote Originally Posted by Micron View Post
    The terminology and description in the OP might be a problem here. First, a form has no "lock" (or enabled) property so what is meant by
    However, the sf control has these. If pressed, I probably would have said the event won't fire if a control was disabled, but I suppose it makes sense where f'rinstance, you want to enable it if you hold a certain user profile. I'm afraid that I don't see the point in the suggestions that basically exit an event regardless, because Lhoj says the event is sometimes needed to open other forms. Now if we knew what condition(s) needs to be tested and what needs to happen as a result of each condition we could probably wrap this up quickly.
    Tbh, Micron, I don't recall if I locked the form or the control. If the form can't be locked then it probably was the control. But what I can say 100% is that disabling the field isn't stopping the event, while disabling the form is. Anyway, the conditions are pretty much that if the form is called from a main menu, the functionalities are all present and the records all navegable. But from other forms that might call the same form it opens just for the required record (not allowing navigation) and I wanted to disable the click events on the subforms to prevent infinite looping between forms. Thing is I expected to do it with a simple .disable=true on the field with the event when opening the main form instead of having to check the arguments the main form was open with in the click event of the subform. But since the sooner proved impossible I'm sticking to the latter.

    Thank you all for your input!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Double click event to filter a subform
    By Rzgar in forum Forms
    Replies: 3
    Last Post: 08-31-2019, 08:16 AM
  2. Replies: 6
    Last Post: 05-08-2019, 03:25 PM
  3. Replies: 12
    Last Post: 03-22-2019, 09:42 AM
  4. Replies: 6
    Last Post: 02-28-2017, 09:33 AM
  5. Opening records via Double-Click event on a search form.
    By IncidentalProgrammer in forum Programming
    Replies: 4
    Last Post: 11-21-2014, 03:47 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