|
-
Sep 28th, 2006, 09:48 AM
#1
Thread Starter
Addicted Member
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.
-
Sep 28th, 2006, 09:51 AM
#2
Hyperactive Member
Re: Button Click Problem
 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:
Private Sub Command1_Click()
Dim lbRunCmd As Boolean
If lbRunCmd = False Then
lbRunCmd = True
'... Insert Code Here ...
lbRunCmd = False ' We are done with what we needed to do
End If
End Sub
Last edited by Fedhax; Sep 28th, 2006 at 09:52 AM.
Reason: Correct VB Code Problem
-
Sep 28th, 2006, 09:53 AM
#3
Thread Starter
Addicted Member
Re: Button Click Problem
I have done this and it has decrease the frequency, but I still occasionly get the RUN TIME error.
-
Sep 28th, 2006, 09:53 AM
#4
Fanatic Member
Re: Button Click Problem
Disable your button, so the user can't click it twice.
VB Code:
Command1.Enabled = False 'at the begin of the click-procedure
Command1.Enabled = True 'at the end of the click-procedure
-
Sep 28th, 2006, 09:58 AM
#5
Thread Starter
Addicted Member
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.
-
Sep 28th, 2006, 10:03 AM
#6
Hyperactive Member
Re: Button Click Problem
 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.
-
Sep 28th, 2006, 10:20 AM
#7
Thread Starter
Addicted Member
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.
-
Sep 28th, 2006, 12:42 PM
#8
Re: Button Click Problem
 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:
Private Sub Command1_Click()
Dim lbRunCmd As Boolean
If lbRunCmd = False Then
lbRunCmd = True
'... Insert Code Here ...
lbRunCmd = False ' We are done with what we needed to do
End If
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:
Private Sub Command1_Click()
Dim b As Boolean
If Not b Then
b = True
Debug.Print "click"
Command1_Click
b = False
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|