Results 1 to 4 of 4

Thread: disable controls

  1. #1

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721

    disable controls

    Hi

    I have this code in vba which I would Like to use to disable all textbox controls
    on my form but it does not work...can anyone help?

    Set frmcurrent = Form_frm_EditQuotes
    For Each ctlContol In frmcurrent.Controls
    If frmcurrent.Controls = acTextBox Then
    Form_frm_EditQuotes.AllowEdits = False
    End If
    Next

    thanks
    ** HOLLY **

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: disable controls

    Thread moved to Office Development (and VBA) forum

    I'm not sure exactly how this should be done in VBA, but here is your code with the 'obvious' errors corrected:
    Code:
    Set frmcurrent = Form_frm_EditQuotes
    For Each ctlContol In frmcurrent.Controls
      If TypeOf ctlContol Is acTextBox Then
        ctlContol.AllowEdits = False
      End If
    Next

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: disable controls

    Does this help?

    vb Code:
    1. Private Sub CommandButton1_Click()
    2.     Dim cCont As Control
    3.  
    4.     For Each cCont In Me.Controls
    5.         If TypeName(cCont) = "TextBox" Then
    6.             'Disable Control
    7.             cCont.Object.Enabled = False
    8.         End If
    9.     Next cCont
    10.  
    11. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721

    Re: disable controls

    Thanks Si...

    it worked a treat!!

    ** HOLLY **

Posting Permissions

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



Click Here to Expand Forum to Full Width