Hi
I have a form that has many buttons (let us say I have 10 buttons) how to check if I clicked all buttons (I am hiding a button when clicked)?
I have used timer to check every half second to do that but is there a better approch?
Hi
I have a form that has many buttons (let us say I have 10 buttons) how to check if I clicked all buttons (I am hiding a button when clicked)?
I have used timer to check every half second to do that but is there a better approch?
Why the need to check. If you can see one then it hasn't been clicked. What kind of thing happens when the buttons are clicked. Just curious.
If this helped, please click the star at the bottom left of this posting and add to my reputation. Many thanks.
Bob Fitzpatrick
Cycle through them and see if they are visible.
Increment a counter in each click event and check for it's value.
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
I'll wager this is because there are a lot more than 10 and some sort of condition exists depending whether or not they've all been clicked. Otherwise I'm with Bob, wondering why one cannot just go by eye. Anyway, this is a common topic - looping through controls - and has been covered here and elsewhere many times. In this case you'd check their visible property, but not every half second. That seems unnecessary.
If you want more focused answers you'll have to explain what is going on. Note that I didn't say explain why checking every .5 seconds is necessary because it's likely not, and doing so may not help to arrive at a practical solution. If it was actually necessary, then I'd agree with the counter idea.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
Many things in Access can store any state you want for your button. For example, you can store the date the button was clicked in its tag property and the timer event could watch all the buttons on the form, so if a button has a date set, it shows how many seconds are left until the button turns off. When the countdown hits zero, the button disables itself and the tag is cleared.
Code:Private Sub Comando6_Click() InformClickInTag Me.Comando6 End Sub Private Sub UpdateCommandButton(cmd As CommandButton) If cmd.Tag <> "" Then Dim disableTime As Date disableTime = CDate(cmd.Tag) Dim timeLeft As Long timeLeft = GetTimeLeft(disableTime) If timeLeft <= 0 Then DisableCommandButton cmd Else cmd.Caption = "Disabling in " & timeLeft & "s" End If End If End Sub Private Function GetTimeLeft(disableTime As Date) As Long GetTimeLeft = DateDiff("s", Now, disableTime) + 5 End Function Private Sub DisableCommandButton(cmd As CommandButton) cmd.Enabled = False cmd.Caption = "Disabled" cmd.Tag = "" End Sub Private Sub Form_Timer() Dim ctrl As Control For Each ctrl In Me.Controls If TypeOf ctrl Is CommandButton Then UpdateCommandButton ctrl End If Next ctrl End Sub Private Sub InformClickInTag(cmd As CommandButton) cmd.Tag = Now End Sub
Please click on the ⭐ below if this post helped you.
↓