How to disable all click events?

deko

New member
Local time
Today, 15:45
Joined
Feb 12, 2010
Messages
9
I have subform datasheet that opens the Office File Picker Dialog when an empty field is clicked (user picks file, filename inserted into datasheet).

The problem is once the dialog is opened, it is positioned directly over several controls on the Parent form that have OnClick events.

When the user double clicks an item in the Office File Dialog, the control behind the Dialog (on the parent form) is getting a click event as the Dialog closes.

How do I prevent these rogue click events? Can I temporarily disable all click events on the main form while the file picker code is running?

I've used code to disable some commonly affected controls on the parent form while the Dialog is open, but the Dialog can be moved by the user. I would have to disable every control on the parent form for this to be effective.

In pseudo code, I'd like to do something like this:

Code:
set frm = Forms(Parent Form)
set dlg = Office File Dialog
frm.ClickEvents.Enabled = False
With dlg
    Me!FileName = dlg.SelectedItems
End With
If dlg.Closed Then
    frm.ClickEvents.Enabled = True
End If
Is there anyway to do something like this? Other suggestions?

Thanks in advance.
 
If you want to temporarily disallow on click events you do this:

Code:
button1.OnClick = ""

Setting it back is this (if you used vba code):
Code:
button1.OnClick = "[Event Procedure]"

If you want to disable all the controls on your form (that have the Enabled property), then you need to iterate through the Controls collection of the form.
 
Yes, I could loop through all the controls on the parent form and disable them or something, but that's a serious hack, not to mention I have lots of controls on the parent form. And I can't disable the subform or it will not receive the ItemsSelected from the Dialog.

I think this is a bug with the Office File Picker Dialog. Perhaps the best way around it is to set a TempVar just before calling the Dialog, and clearing it immediately after the Dialog closes.

Then I could do something like this in each control's click event:

Code:
cmdParentFormControl_Click()
     If TempVar("dlg") Then Exit Sub
     [existing click event code here]
End Sub
Still a hack, but I don't know any other way around it.
 
It would be interesting to see if anyone else can duplicate this. I have Kingston Expert Mouse using Vista drivers on Win7 that could be the problem. I will test with another mouse...
 
It's a dialog window, it's supposed to have focus and not allow any other window to be used until closed. Could be a bug there. There are a few ways you can loop through your control using the Controls collection but I think this is your best bet:

1. Highlight all the buttons you would want to be disabled and set their Tag property to something like "disableMe"
2. Use this code:

Code:
    Dim ctl as Control
    For Each ctl In Me
        If ctl.Tag = "disableMe" Then
            ctl.enabled = False
        End If
    Next

Remember, that will only work for controls that have the Enable property (e.g. it will throw up an error if you try to use it for labels because they cannot be disabled)
 
tried with a different mouse. same problem.

if the dialog could be configured to ignore double clicks that should fix it (user would have to click "OK" rather than double clicking item)

wondering if adjusting click speed in the OS would help...
 
I doubt you saw my post above. Regarding setting the dialog control to accept only double clicks then you are talking beyond File Dialog control, more like APIs.
 
Just hide the other form when the dialog is opened via code and then set the form visible again when the dialog is closed. It might help.
 
what IS the dialog box?

a msgbox?

roll your own msgbox - then you can control the clicks

--------------
or - position the dialog box in a "safe" area of the screen.
 
Thanks for the replies.

It's definitely an issue with the dialog.

If the user double clicks an item in the dialog rather than selecting an item and clicking OK, the double click passes a single click to whatever control is directly behind the area double clicked.

For a work around I used a TempVar and error handling code that logs each time it happens.

TempVar("FilePicker") is set to True before calling the File Picker Dialog and to False when the Dialog closes.

Code:
myControl_Click()
    On Error GoTo CustomHandler
    If GetTempVar("FilePicker") Then Err.Raise ROGUE_CLICK
    [existing code]
    ...
CustomHander:    
    If Err.Number = ROGUE_CLICK Then
        [log form and procedure]
        Exit Sub
    End If
End Sub
I'm huntin wabbits...
 
It could be your Windows settings. Do you normally open files with one click or double? Using your idea, do that in the Mouse Down event of the form, counting how many clicks and only acting on the event if the number of clicks is one.
 
No, it's not my windows settings. I pretty sure it's the dialog closing too soon, before the OS has processed the double click.

hmmm... I'll try a couple of DoEvents statements

Another possible work around might be to get the mouse x/y coordinates on mouse down and ignore clicks in that area until the dialog closes.
 
Here's a scrubbed version.

What you don't see are some Application.Echo statements surrounding this code... I have a hunch that is the culprit, but have not tested yet. DoEvents didn't help.

Code:
    Set dlg = Nothing
    Set fso = New Scripting.FileSystemObject
    Set db = CurrentDb
    Set qdfs = db.QueryDefs
    Set qdf = qdfs("qryDocsInsertNew")
    Set dlg = FileDialog(msoFileDialogFilePicker)
    Call SetupDialog(dlg, lngEid, strDocDir)
    If dlg.Show = True Then
        indx = 0
        For Each varFile In dlg.SelectedItems
            If Len(varFile) > 0 Then
                strCurrentPath = varFile
                strFileName = fso.GetFileName(strCurrentPath)
                strNewPath = strDocDir & "\" & strFileName
                fso.MoveFile strCurrentPath, strNewPath
                DoEvents
                'sanity check
                If Not fso.FileExists(strNewPath) Then Err.Raise LINK_FAILURE
                'insert link in database
                qdf.Parameters("prmFileName") = strFileName
                qdf.Parameters("prmFilePath") = strNewPath
                qdf.Parameters("prmEid") = lngEid
                qdf.Execute dbFailOnError
                blnNewDoc = True
            End If
Next_File:
        Next
    Else 'validate and open file
        If fso.FileExists(strCurrentPath) Then
            Call modOpenFile.OpenFile(strCurrentPath)
        Else
            MsgBox "Could not find: " & vbCrLf & vbCrLf & _
                strCurrentPath, vbExclamation, " Document Not Found"
        End If
    End If
 
Nope.

Not the Application.Echo statements.

will try to duplicate on another computer...
 
Have you tried the suggestion from SOS?

Also, try uncommenting all the code (except the open dialog, and select file action) and see if it still does the same thing
 
Behind the Sub Form: -
Code:
Private Sub WhateverYouAreDoing()

    On Error GoTo ErrorHandler
    
    SetClickHandlers Me.Parent, False
    
    [color=green]' Do
    ' whatever
    ' you
    ' are
    ' doing[/color]
    
ExitProcedure:
    SetClickHandlers Me.Parent, True
    Exit Sub
    
ErrorHandler:
    MsgBox Err.Number & "   " & Err.Description
    Resume ExitProcedure

End Sub


In a Standard Module: -
Code:
Option Explicit
Option Compare Text


Public Sub SetClickHandlers(ByRef frmForm As Access.Form, _
                            ByVal intState As Integer)
                     
    Dim ctlControl As Control
    
    [color=green]' Ignore any control without an OnClick event.[/color]
    On Error Resume Next
    
    If (intState) Then
        [color=green]' Restore the OnClick event handlers.[/color]
        For Each ctlControl In frmForm
            ctlControl.OnClick = ctlControl.Tag
        Next ctlControl
    Else
        [color=green]' Save and Clear the OnClick event handlers
        ' even if they are not used.[/color]
        For Each ctlControl In frmForm
            ctlControl.Tag = ctlControl.OnClick
            ctlControl.OnClick = ""
        Next ctlControl
    End If

End Sub
 
i can see what is happening - you have a msgbox, and dble-click a button

so it closes with the first button, and then uses the second click.

Maybe its not even a dble-click - maybe its 2 clicks close together.

-----------
To get round this, as I say, you need to

a) train the guys
b) positiion the msgbox in a safe area of the form
c) write your own msgbox function, as Chris as demosnstrated above
 
thanks for the feedback! sorry for delay in response...

SOS suggested:

"hide the other form when the dialog is opened via code and then set the form visible again when the dialog is closed"

Yep, this would prevent the rogue click for doing anything. but there are reasons why this is not practical in the Access application in question.

ChrisO suggested:

Loop through all controls and modify OnClick event before and after dialog code runs.


Yep, another way to handle the rogue click. but I think it's a rather risky work around.

gemma-the-husky thinks I have a message box, while the dialog in question is instead the Office FileDialog.

This Dialog is part of the Microsoft Office 12.0 Object Library. My app has a reference to this library (MSO.DLL).

instantiated like this:

Code:
Dim dlg As Office.FileDialog
Set dlg = FileDialog(msoFileDialogFilePicker)
The problem happens when the user double clicks an item in the dialog. The double click selects the item and closes the dialog, but leaves behind a single click which is received by whatever control is directly behind the dialog in the area that was doubled clicked.

Training users is like herding cats and positioning the dialog would be far more involved than other solutions (not to mention need to manage Access application window position as well as dialog)

Here's what I came up with:

added this line of code to event handler of each control at risk of receiving rogue click:

Code:
If GetTempVar("FilePicker") Then Err.Raise ROGUE_CLICK
and surround dialog code with this:

Code:
Call SetTempVar("FilePicker", True)
[dialog code]
Call SetTempVar("FilePicker", False)
I have functions that Get/Set the TempVar and code that handles ROGUE_CLICK errors.

I like this because it's minimally invasive and robust enough for a production environment.

In any case.... still think it's a bug in the Dialog... current config is AC2007 on 64-bit Win7. testing to see if I can duplicate on other hardware/OS configs...
 

Users who are viewing this thread

Back
Top Bottom