Results 1 to 5 of 5
  1. #1
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57

    How to check for condition in a form


    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?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by rwahdan1978 View Post
    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

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    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

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    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.

  5. #5
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    309
    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
    Attached Files Attached Files
    Please click on the ⭐ below if this post helped you.


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

Similar Threads

  1. Check box in query condition: is this possible?
    By WesHarding in forum Queries
    Replies: 7
    Last Post: 03-22-2017, 11:30 AM
  2. Replies: 41
    Last Post: 12-06-2016, 08:40 AM
  3. Replies: 18
    Last Post: 06-20-2014, 12:13 PM
  4. autofill from with specific condition check
    By dhanesh.koshti in forum Access
    Replies: 3
    Last Post: 01-14-2014, 01:01 PM
  5. Replies: 35
    Last Post: 01-08-2014, 01:33 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