Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lock controls (A2k SR1)

    Is it possible to lock all controls, texts, buttons on a form dependant on criteria.

    My main form has a text [Status] containing one letter info. "U", "A", "C", "I", "F"
    From the main form, many other forms can be opened via menu's.
    I want lo lock certain forms depending which letter is shown on the main form.
    I know I can do this with each control individually but its a big pain. ie

    If Forms!frmDetails!Status = "F" then Me.[SomeTextorButton1].Locked = True
    If Forms!frmDetails!Status = "F" then Me.[SomeTextorButton2].Locked = True
    If Forms!frmDetails!Status = "F" then Me.[SomeTextorButton3].Locked = True
    If Forms!frmDetails!Status = "F" then Me.[SomeTextorButton4].Locked = True
    If Forms!frmDetails!Status = "F" then Me.[SomeTextorButton5].Locked = True
    If Forms!frmDetails!Status = "F" then Me.[SomeTextorButton6].Locked = True
    etc etc etc.

    I would rather

    If Forms!frmDetails!Status = "F" then "All Controls".Locked = True

    Does any one have a module I can call from any form ?? and how would I implement it.

    Regards

    Dave

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Lock controls (A2k SR1)

    You can set the form's "allow edits" property to False and this will achieve much the same thing.

    Command buttons don't have a locked property, only an enabled property. Do you want them disabled as well?
    Setting the "allow edits" property won't affect the command buttons.
    Regards
    John



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

    Re: Lock controls (A2k SR1)

    Try calling something like this:

    <pre>Private Sub LockAllControls()
    Dim ctl As Control

    For Each ctl In Controls
    Select Case ctl.ControlType
    Case acTextBox, acCheckBox, acComboBox, acToggleButton, _
    acListBox, acOptionGroup, acSubform
    ctl.Locked = True
    Case acCommandButton, acTabCtl
    ctl.Enabled = False
    Case Else
    'skip lines, boxes, bound frames, etc.
    End Select
    Next ctl
    End Sub</pre>

    Charlotte

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Lock controls (A2k SR1)

    Thanks Charlotte thats exactly what I needed.
    Just on thing, I recognise how the code see's the objects:

    acTextBox, acCheckBox, acComboBox, acToggleButton, acListBox, acOptionGroup, acSubform

    I also have Date&Time pickers on a couple of forms which are still active, how do I refer to these :

    acActiveX ?????

    Regards Dave

  5. #5
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Lock controls (A2k SR1)

    Thanks Charlotte,

    You have just made my life simpler. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Regards,

    Gary
    (It's been a while!)

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

    Re: Lock controls (A2k SR1)

    Sorry to disappoint you, but ControlType only applies to Access controls. ActiveX controls are something else, so you can't use controltype to recognize them. The object does have a Locked property, though, so you can add a line to lock it specifically.
    Charlotte

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

    Re: Lock controls (A2k SR1)

    Any time, Gary. <img src=/S/bow.gif border=0 alt=bow width=15 height=15>
    Charlotte

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Lock controls (A2k SR1)

    Thanks Charlotte, your method works fine.
    I used Enabled instead because my D&T picker is set to dropdown automatically dependant on another Fields Null value.

    Many thanks

    Dave

Posting Permissions

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