Results 1 to 3 of 3
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    Syntax to make command bar button visible

    I've created a command bar for right click on a control in a form with something like this:
    (it's been hacked together here for demonstration from different procedures and forum suggestions)

    Code:
    Dim cbrRc As Object
    Set cbrRc = fResetCbr(Fcntl(1, 15)) 'Fcntl(1,15) has a name for the control bar right click menu
    
        With cbrRc.Controls.Add(msoControlButton)
          .Caption = fTranltLang(TempVars!LoLangID, "3_RcfSearch", "LF") 'Translates the button into different languages
          .OnAction = "=f" & Fcntl(1, 15) & "Search()" 'The function name is built for use in the form class module
          .Enabled = False
        End With
        'more buttons added below
    ---
    Public Function fResetCbr(aBarName As Variant) As Office.CommandBar
      'Delete bar if it exists, must be called with set from another procedure
    
      On Error Resume Next
      CommandBars(aBarName).Delete
    
      On Error GoTo 0
      Set fResetCbr = CommandBars.Add(aBarName, 5) ', False, True)
    
    End Function
    In another procedure for a form control, I need to make the "Search" button enabled.
    I'm going cross-eyed trying to figure out the syntax to modify just that one button.
    What is the syntax?


    Is there also a way to "id" the "Search" button, so I can reference it in a simpler manner (than the foreign language caption)?

    Thanks
    Last edited by twgonder; 05-21-2023 at 02:58 AM. Reason: clarify

  2. #2
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    I think I got it with this:
    Code:
    CommandBars(Fcntl(1, 15)).Controls(1).Enabled = True
    I am a little confused by Controls(1). Since most things in Access are 0 based, and this was the first button added to the command bar, I'm wondering if the "(1)" might mean something else, or if I just got lucky.

  3. #3
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    You can also use this syntax Controls.Item("ControlName")

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

Similar Threads

  1. Use option button to make textbox not visible
    By Stephenson in forum Programming
    Replies: 4
    Last Post: 10-05-2015, 03:40 PM
  2. Replies: 1
    Last Post: 02-27-2015, 10:01 AM
  3. Replies: 1
    Last Post: 12-28-2013, 12:38 PM
  4. Replies: 1
    Last Post: 12-19-2012, 08:09 PM
  5. make fields visible onclick() button
    By rivereridanus in forum Programming
    Replies: 4
    Last Post: 06-25-2012, 11:08 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