Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2015
    Posts
    3

    Answered: Making a form Read-only lockup Option buttons...

    Hi all
    First post ... on here - a useful source of collective knowledge, which has helped me with other items.
    However I have searched without any success to find a workable solution.

    I have a form 'Tabs' which displays selected fields from a query (linked tables) which is often used for data search, it has an Option Button select feature on the form, which filters the data into specific blocks.

    However the form needs to open in Read only to protect the data from any inadvertent corruption. In attempt to code this in VBA (see code below ...)
    it also locks up the option button feature.
    I have tried to set the toggle to 'no lock' but that does not help.

    Private Sub Toggle230_AfterUpdate()
    If Me.Toggle230 = True Then
    Forms!Tabs.AllowAdditions = True
    Forms!Tabs.AllowEdits = True
    Forms!Tabs.AllowDeletions = True
    Toggle230.Locked = No
    MsgBox "un-locked"
    Else
    Forms!Tabs.AllowAdditions = False
    Forms!Tabs.AllowEdits = False
    Forms!Tabs.AllowDeletions = False
    Toggle230.Locked = No
    MsgBox "locked"
    End If
    End Sub

    any ideas to fix this please. no doubt there will be a simple fix !
    thanks.

  2. Best Answer
    Posted by Missinglinq

    "You can't do this with AllowEdits, etc, you need to Lock or Lock and Disable all Controls except the one(s) you want to remain usable.

    Here's a quick tutorial I ran up a while ago:

    In Design View, select the Control(s) you want to be functioning and go to Properties-Other and in the Tag Property box enter DoNotLock, just like that, no quotes.

    Then place this code in the code window:
    Code:
    Private Sub Form_Current()
    Dim ctrl As Control
    
     For Each ctrl In Me.Controls
        If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is CheckBox) Or (TypeOf ctrl Is ComboBox) Or (TypeOf ctrl Is OptionGroup) Then
         If ctrl.Tag <> "DoNotLock" Then
           ctrl.Enabled = False
           ctrl.Locked = True
         Else
           ctrl.Enabled = True
           ctrl.Locked = False
         End If
        End If
      Next
    End Sub
    This method can be used to do other things, as well, such as looping Controls to do Validation of selected ones, before saving a Record. You can also add other types of Controls in the

    If (TypeOf ctrl Is TextBox)

    line if need be. The only caveat is you that you need to be sure that the types of Controls you're looping thru actually have the Properties you're setting! If, for instance, you used the above code but included TypeOf ctrl Is Label you'd pop an error! That's because Labels do not have Enabled or Locked Properties!

    Linq ;0)>"


  3. #2
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    495
    Provided Answers: 24
    in the form propeties,
    set the Toggle230.value = false
    AllowAdditions = False
    AllowEdits = False
    AllowDeletions = False

    save. Now these are the defaults.

  4. #3
    Join Date
    Sep 2015
    Posts
    3

    Making a form Read-only that doesn't lockup Option buttons...

    Hi Ranman,
    thanks for the response on this one...
    I think in my excitement with my first post made a small error in the title..ooops.

    What I'm seeking is a way to toggle on and off the RO/RW to protect the data fields but 'Doesn't ' lockup some filter option buttons on the form.
    apologies for this - as indeed setting defaults as you suggest would stop any inadvertent changes but this does lock the filters and the toggle button.

    I have made a small change to the VBA; as I was using 'no' instead of False. I also added in the name of the option box - 'selectme' and set to False too.
    This still fails to give the desired result

    again any advice would be welcome.

    Private Sub Toggle230_AfterUpdate()
    If Me.Toggle230 = True Then
    Forms!Tabs.AllowAdditions = True
    Forms!Tabs.AllowEdits = True
    Forms!Tabs.AllowDeletions = True
    MsgBox "un-locked"
    Else
    Forms!Tabs.AllowAdditions = False
    Forms!Tabs.AllowEdits = False
    Forms!Tabs.AllowDeletions = False
    Toggle230.Locked = False
    selectme.Locked = False
    MsgBox "locked"
    End If
    End Sub


    thank you.

  5. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You can't do this with AllowEdits, etc, you need to Lock or Lock and Disable all Controls except the one(s) you want to remain usable.

    Here's a quick tutorial I ran up a while ago:

    In Design View, select the Control(s) you want to be functioning and go to Properties-Other and in the Tag Property box enter DoNotLock, just like that, no quotes.

    Then place this code in the code window:
    Code:
    Private Sub Form_Current()
    Dim ctrl As Control
    
     For Each ctrl In Me.Controls
        If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is CheckBox) Or (TypeOf ctrl Is ComboBox) Or (TypeOf ctrl Is OptionGroup) Then
         If ctrl.Tag <> "DoNotLock" Then
           ctrl.Enabled = False
           ctrl.Locked = True
         Else
           ctrl.Enabled = True
           ctrl.Locked = False
         End If
        End If
      Next
    End Sub
    This method can be used to do other things, as well, such as looping Controls to do Validation of selected ones, before saving a Record. You can also add other types of Controls in the

    If (TypeOf ctrl Is TextBox)

    line if need be. The only caveat is you that you need to be sure that the types of Controls you're looping thru actually have the Properties you're setting! If, for instance, you used the above code but included TypeOf ctrl Is Label you'd pop an error! That's because Labels do not have Enabled or Locked Properties!

    Linq ;0)>
    Last edited by Missinglinq; 09-15-15 at 18:44.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #5
    Join Date
    Sep 2015
    Posts
    3

    Smile fixed !

    Hi Missinglinq,

    that's a superb fix - I didn't know that could be done !
    I just need to remember to add the tag to any additional fields etc I decide to add on the form.

    Brilliant work - thanks very much.

    --not sure how to mark this as answered...
    Last edited by jacksocket; 09-17-15 at 12:58.

  7. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad we could help!

    FYI, click on the 'Best Answer" button on a given post to show that it has answered your problem. I went ahead and did that for you.

    Linq ;0)>
    Last edited by Missinglinq; 09-17-15 at 13:22.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Tags for this Thread

Posting Permissions

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