Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enable controls (Access 2000)

    I want to enable and disable controls with the help of the excellent code suggested by Hans, from the form where i open another form,but somehow i cannot refer to this form. The control is in the form Form1, and i want to enable controls in the form "frmWarehouse". How can i do it from the form Form1?


    stDocName = "frmWarehouse"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Call EnableControl(stock, true.items,true)


    Private Sub EnableControl(ControlName As String, Flag As Boolean)
    With CodeContextObject.Controls(ControlName)
    .Locked = Not Flag
    .Enabled = Flag
    .Visible = Flag
    End With
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Enable controls (Access 2000)

    The EnableControl procedure only works for the form from which it is called, not for another form.
    Replace the line

    Call EnableControl(stock, true.items,true)

    (which is not correct anyway) with

    With Forms(stDocName).Controls("nameofcontrol")
    .Locked = False
    .Enabled = True
    .Visible = True
    End With

    where nameofcontrol is the name of the control that you want to enable.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Enable controls (Access 2000)

    Thank you Hans ! The code is really perfect ! Just a small question.Writing the controls, i can write only one control and not more for example
    With Forms(stDocName).Controls("Bestand")
    .Locked = False
    .Enabled = True
    .Visible = True
    End With
    I would like to add more controls in the same line for example With Forms(stDocName).Controls("Bestand","Stueck","grad e").Is it possible ? it seems i am no alowed to do it

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Enable controls (Access 2000)

    No, you can't. You'll have to repeat the lines for each control (or write a new function).

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Enable controls (Access 2000)

    You could create a procedure like this in a standard module:

    Sub EnableControl2(FormName As String, ControlName As String, Flag As Boolean)
    With Forms(FormName).Controls(ControlName)
    .Locked = Not Flag
    .Enabled = Flag
    .Visible = Flag
    End With
    End Sub

    and call it like this:

    Call EnableControl2(stDocName, "Bestand", True)
    Call EnableControl2(stDocName, "Stueck", True)
    Call EnableControl2(stDocName, "Grade", True)

  6. #6
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Enable controls (Access 2000)

    Thank you Hans. I have noted that.Excellent code

Posting Permissions

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