Results 1 to 8 of 8

Thread: Button Click Problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Button Click Problem

    I have a routine that when the user clicks on a button the first thing that it does is look to see if a certain data file is open and if it is delete it, then do some setup code, then open the data file again, put data into it and then exit the routine. I have found that if the user raplidly clicks the button that once in a while a RUN TIME error is generated. I have traced this down to what I think is that XP is trying to delete and open the same data file at the same time. I belive that if the user clicks on the button fast enough that multi-instances of the routine are started that can cause the conflit.

    Is there a way that once the user enters the routine, that I can lock the routine from triggering agian until I am finished with the routine?

    I have a similar problem with a routine that is called when the user clicks on an thumbnail. Here the routine sets up and displays the associated image file. Again if the user rapidly clicks on various thumbnails, I think once in a while two instances get started and XP can not load two image files at the same time and again a RUN TIME error is generated.
    Last edited by JohnDonaldson; Sep 28th, 2006 at 09:52 AM.

  2. #2
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Button Click Problem

    Quote Originally Posted by JohnDonaldson
    Is there a way that once the user enters the routine, that I can lock the routine from triggering agian until I am finished with the routine?
    Use a global or form level boolean variable to control if/when the button's event can be used:
    VB Code:
    1. Private Sub Command1_Click()
    2.    Dim lbRunCmd      As Boolean
    3.  
    4.    If lbRunCmd = False Then
    5.       lbRunCmd = True
    6.  
    7.       '... Insert Code Here ...
    8.  
    9.       lbRunCmd = False  ' We are done with what we needed to do
    10.    End If
    11. End Sub
    Last edited by Fedhax; Sep 28th, 2006 at 09:52 AM. Reason: Correct VB Code Problem

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: Button Click Problem

    I have done this and it has decrease the frequency, but I still occasionly get the RUN TIME error.

  4. #4
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: Button Click Problem

    Disable your button, so the user can't click it twice.
    VB Code:
    1. Command1.Enabled = False 'at the begin of the click-procedure
    2.  
    3. Command1.Enabled = True 'at the end of the click-procedure

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: Button Click Problem

    This may work for the first part, but not the thumnail problem. The thumbnails is an ActiveX control, each time you click on a thumbnail an assocaited routiine is called. This routine returns the Index Number and Assoicated File_Name of the thumbnail. I don't think there is a way to de-enable the thumbnail ActiveX like you can a button.

  6. #6
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Button Click Problem

    Quote Originally Posted by JohnDonaldson
    This may work for the first part, but not the thumnail problem. The thumbnails is an ActiveX control, each time you click on a thumbnail an assocaited routiine is called. This routine returns the Index Number and Assoicated File_Name of the thumbnail. I don't think there is a way to de-enable the thumbnail ActiveX like you can a button.
    If this scenario is the case, it was an under-implemented user control to not include the ability to disable it. You will probably be left with my solution to stop the problem. You may also need to step through the code and add additional error checking to circumvent the problem sections--like it is opening a file that doesn't exist--or handle the errors more gracefully. There isn't going to be a magical bullet to stop this process if you can't nip it in the bud at the beginning.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: Button Click Problem

    I was afraid of that......thanks for all the replies......Under normal use, I don't think the user will be machinegunning clicking of the Thumbnails, but one never knows what users do. LOL

    I am going to asked the company we got the ActiveX control from if there is something that I can use to help stop this problem. I am sure they may have not thought of this Scenario.

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Button Click Problem

    Quote Originally Posted by Fedhax
    Use a global or form level boolean variable to control if/when the button's event can be used:
    VB Code:
    1. Private Sub Command1_Click()
    2.    Dim lbRunCmd      As Boolean
    3.  
    4.    If lbRunCmd = False Then
    5.       lbRunCmd = True
    6.  
    7.       '... Insert Code Here ...
    8.  
    9.       lbRunCmd = False  ' We are done with what we needed to do
    10.    End If
    11. End Sub
    That code won't do anything, since lbRunCmd will always be False - you can show it by making the sub recursive:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim b As Boolean
    3.     If Not b Then
    4.         b = True
    5.         Debug.Print "click"
    6.         Command1_Click
    7.         b = False
    8.     End If
    9. End Sub
    if you change the Boolean declaration to be Static, then it will work: Static b As Boolean

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width