Results 1 to 7 of 7

Thread: enable controls

  1. #1
    Join Date
    Apr 2004
    Posts
    100

    Unanswered: enable controls

    hi,

    by using form.enabled = false I can disable the whole form, however it, and especially its controls, are not marked grey.
    how can i accomplish that the form and all its controls are disabled and marked grey?

    Thanks in advance,
    Proximus

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Use a for each ..... Loop

  3. #3
    Join Date
    Apr 2004
    Posts
    100
    i've tried. any ideas why the code below doesn't work?

    Private Sub Command8_Click()
    Dim ctl As Control
    For Each ctl In Me.Controls
    ctl.Enabled = False
    Next
    End Sub

  4. #4
    Join Date
    Jul 2004
    Location
    Inverurie
    Posts
    628
    a bit of a noob question this, but that procedure seems to be a never ending loop. Couldn't you just call each control by name and disable them? You could then change the colour of them to grey (including the labels).

    If you wanted to be really flash i suppose there is a way to get them removed from the Tab order list too, so that way there's no chance of the users getting to select them until they are enabled.

  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    Here is a function I use to enable or disable a control on a form
    PHP Code:
    Function HideAnyControl(thisForm As StringthisControl As StringlHide As Boolean)
      
    ' CreatedOn:07.07.2004
      
       Dim frm As Form
       Dim Ctrl As Control
         Set frm = Forms(thisForm)
           If thisControl = "TextBox" Then
             For Each Ctrl In frm.Controls
               If Ctrl.ControlType = acTextBox Then
                 If lHide Then
                    Ctrl.Visible = False
                 Else
                    Ctrl.Visible = True
                 End If
              End If
             Next
          End If
           
      Set frm = Nothing


    End Function 

  6. #6
    Join Date
    Apr 2004
    Posts
    100
    that's exactly what i was looking for.
    Many thanks hammbakka !!!!
    @cruisehanks: the loop ends when there is no more control in the controls collection left

  7. #7
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Also you have to take into consideration, the type of the control

Posting Permissions

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