Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jun 2009
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enable/Disable Buttons on Switchboard

    Hello,
    I have two buttons on my switchboard that allow the user to perform two functions:

    1. The first button allows the user to run a query to see if there are any records that need updated. Basically I have the following code that runs on the macro:

    Code:
    Option Compare Database
    
    
    Function AuditRecords(strQuery As String)
    
    
    Dim strMSG As String, lngRecs As Long
    
    
    lngRecs = DCount("*", strQuery)
    
    
    If lngRecs = 0 Then
        strMSG = "No missing data found."
    Else
        strMSG = lngRecs & " record(s) found."
    End If
    
    
    MsgBox strMSG, vbInformation
    
    
    End Function
    2. The second button basically opens the update query.

    Is there a way to disable the second button if there are no records to update?

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts

    A possible solution.

    Code:
    Option Compare Database
    
    
    Function AuditRecords(strQuery As String)
    
    
    Dim strMSG As String, lngRecs As Long
    
    
    lngRecs = DCount("*", strQuery)
    
    
    If lngRecs = 0 Then
        strMSG = "No missing data found."
        forms("Switchboard").option2.visible = false
    '*** Note change option2 to optionx where x = relative no of the option on the menu.
    Else
        strMSG = lngRecs & " record(s) found."
    End If
    
    
    MsgBox strMSG, vbInformation
    
    
    End Function
    Notes:
    1. If you navigate to another page in in the switchboard and then return all options will be shown.
    2. If you add/delete options on the switchboard page you will have to manually adjust the optionx value.

    I hope this helps or at least gets you closer to where you want to be.
    Attached Images Attached Images
    Last edited by RetiredGeek; 2011-06-24 at 13:20. Reason: Add attachment
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    You can use the Activate event to run code each time you return to the Switchboard after doing something else.
    You can choose whether to hide the button or simply disable it.

    Sometimes I find it useful to put a small unbound textbox next to the command button and display the count of records in that. That is what the last line of code does.

    Code:
    Dim lngRecs As Long
    Dim strquery as string
    strquery = "qryxxx"   
    lngRecs = DCount("*", strQuery) 
    If lngRecs = 0 Then       
          forms("Switchboard").option2.visible = false
           forms("Switchboard").option2.enabled = false 
     '*** Note change option2 to optionx where x = relative no of the option on the menu. 
    Else        
           forms("Switchboard").option2.visible = true
            forms("Switchboard").option2.enabled = true     
    End If 
    me.txtcount = lngRecs
    Last edited by johnhutchison; 2011-06-24 at 19:06.
    Regards
    John



  4. #4
    Star Lounger
    Join Date
    Jun 2009
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perfect. Thanks again!

Posting Permissions

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