Results 1 to 13 of 13
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    disable controls (Access 2000)

    I have an excellent fucntion, copied from Hans, to disable the controls on a form. This function disables also the command buttons,
    but when i go to a record that does not meet the conditions, the command buttons remain disabled, and they should be enabled.It concerns only the command buttons, the textbox controls are OK.

    Dim ctl As Control
    ' Not all controls can be disabled - prevent errors
    On Error Resume Next
    If Me!MyCustomer = True Then
    ' Loop through all controls
    For Each ctl In Me.Controls
    ctl.Enabled = False
    Next ctl
    Set ctl = Nothing
    ' then enable specific ones
    Me.CmdOn.Enabled = True
    Me.CmdFro.Enabled = True
    Me.Customerid.Enabled = True
    End If


    I tried then to use the constants acComandButton but but i had no success.The command buttons remain disabled all the time. Can somevody show me where is my error in the following function?

    Dim ctl As Control
    ' Not all controls can be disabled - prevent errors
    On Error Resume Next
    If Me!MyCustomer = True Then
    ' Loop through all controls
    For Each ctl In Me.Controls
    If ctl.ControlType = acCommandButton Then
    ctl.Enabled = False
    End If
    If ctl.ControlType = acTextBox Then
    ctl.Enabled = False
    End If
    Next ctl
    Set ctl = Nothing
    ' then enable specific ones
    Me.CmdOn.Enabled = True
    Me.CmdFro.Enabled = True
    Me.Customerid.Enabled = True
    End If

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: disable controls (Access 2000)

    I don't see where you enable any controls, except the specials.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: disable controls (Access 2000)

    the controls are enabled per default and if the condition is not met, they should stay enabled without any code
    This is as far as i underdtand it, but if you think i am wrong please send me the corrected code as you see it, in order
    to apply it in the form
    regards

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: disable controls (Access 2000)

    You say:
    <<This function disables also the command buttons, but when i go to a record that does not meet the conditions, the command buttons remain disabled, and they should be enabled>>
    Where do you disable these controls, is it a one time in the OnOpen event of the form, or is it in the OnCurrent event.
    If you disable the buttons depending on a record's conditions the goto another record that does not have the disable conditions the disbaled controls are still disabled.
    I must be missing something.

  5. #5
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: disable controls (Access 2000)

    Thank you for your reply. You are right, i have this code in the OnCurrent event. We look through each record to see the actual status of the customer.
    Looking through these records the command buttons remain disabled.Please give me an advice what to do

    Thank you in advance

    regards

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: disable controls (Access 2000)

    I just wanted to add the caution that you need to test the ControlType of each control to make sure it is one that can be enabled/disabled before attempting to do so.
    Charlotte

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: disable controls (Access 2000)

    <P ID="edit" class=small>(Edited by patt on 22-Nov-04 07:12. Changed after Charlotte's advice re ControlType of controls)</P>What you have to do is:

    For each ctl on the form
    if ControlType is Applicable then
    if test is true then
    ctl.Enabled = False
    else
    ctl.Enabled = True
    EndIf
    EndIf
    Next ctl

    Change the code to suit your code.

  8. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: disable controls (Access 2000)

    As always you are spot on, thanks Charlotte.

  9. #9
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: disable controls (Access 2000)

    thank you very much indeed.Such nice replies and a tremendous help !!!

  10. #10
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: disable controls (Access 2000)

    Thank you very much for your kind reply.
    I have pasted your code in the OnCurrent event but i receive the
    message on Applicable that the variable is not found.How can i define it?
    If Me!MyCustomer = True Then
    Dim ctl As Control
    For Each ctl In Me.Controls
    If ctl.ControlType Is Applicable Then
    If test Is True Then
    ctl.Enabled = False
    Else
    ctl.Enabled = True
    End If
    End If
    Next ctl
    End If

  11. #11
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: disable controls (Access 2000)

    In the code below i get the message Compile error sub or function not defined and the error point to EndSelect.
    What may be the reason ?

    Dim ctl As Control
    For Each ctl In Me.Controls
    Select Case ctl.ControlType
    Case acTextBox, acComboBox, acListBox, acCommandButton
    ' Control has an enabled property
    ctl.Enabled = Not Me!MyCustomer
    EndSelect
    Next ctl

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

    Re: disable controls (Access 2000)

    Sorry, that is a typo. It should be End Select instead of EndSelect.

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

    Re: disable controls (Access 2000)

    Edited by HansV - corrected EndSelect to End Select.

    "Applicable" was not meant as a literal Access VBA term here, but as a descriptive term: some controls, such as labels, cannot be enabled/disabled. So you must check whether the Enabled property can be set:

    For Each ctl In Me.Controls
    Select Case ctl.ControlType
    Case acTextBox, acComboBox, acListBox, acCommandButton
    ' Control has an Enabled property
    ctl.Enabled = Not Me!MyCustomer
    End Select
    Next ctl

    You can expand the list of controls if you wish, depending on the controls you have.

Posting Permissions

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