Results 1 to 11 of 11
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Locking a subform

    Is there a way to lock a subform if the main form is not a new record? I use code to keep users from editing a record on a form if it's not a new record.. If Me.NewRecord Then Forms![IDC Receipt Form].AllowEdits = True Else Forms![IDC Receipt Form].AllowEdits = False.. This locks the user from making edits to the main form but not the sub.. How can I lock them out from the subform [ReceiptSubform]? Thanks..

  2. #2
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    188
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking a subform

    How about setting the subforms Enabled property to false when the main form is not in a new record?

    HTH

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

    Re: Locking a subform

    Do you want the users to be able to see the records in the subform, that is, to scroll or browse through them without being able to edit them? If so, you won't be able to do that if you disable the subform. However, you set the AllowEdits. AllowAdditions and AllowDeletions properties of the subform itself to false,which would allow the user to browse the information in the subform but not to change it in any way. You could use the OnCurrent event of the main form to test for a NewRecord condition and use the result of that test to reset the subform properties appropriately.
    Charlotte

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking a subform

    Thanks Charlotte.. I'll check it out..[img]/w3timages/icons/love.gif[/img][img]/w3timages/icons/love.gif[/img]

  5. #5
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    188
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking a subform FORGET WHAT I SAID!

    See what I get for trying to answer that early in the morning! Charlotte, one thing I thought you might catch me on, and I am ashamed I didn't think of it. Simply Enabling and disabling the subform stops the subform from being scrolled etc. Even worse if you follow through with my crazy thinking, simply setting Locked to true for the subform control, does lock it, however, that does not stop one from deleting records in the subform.

    Your method of setting the subforms AllowEdits, AllowAdditions, and AllowDeletions is the way to go.

    I'll give my self a [img]/w3timages/icons/yikes.gif[/img] on that one!!!!!
    Y I K E S ! ! ! Indeed!

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

    Re: Locking a subform FORGET WHAT I SAID!

    Hey, nobody specified that they wanted to be able to scroll the subform, so don't feel bad. An even simpler method, if the user isn't allowed to browse the subform, is to set the visible property of the subform control to false by default and only display the thing when a new record is added in the main form.
    Charlotte

  7. #7
    New Lounger
    Join Date
    Aug 2002
    Location
    Chicago, IL, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking a subform

    I'm having a problem with subforms having their AllowEdits, AllowAdds, and AllowDeletions set to False after opening a main form with DoCmd.OpenForm with the acReadOnly constant specified. After the user browses in the form and then closes it, the subforms' Allow... properties get set to False. Also, any time the main form is opened, whether with acReadOnly or not, all the subforms get resaved (according to the modification date). What's going on?

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

    Re: Locking a subform

    Subforms are controls. If you open a form readonly, wouldn't you expect the subforms to be read only as well? As for the modification date, what version of Access are you using? I don't see that behavior in Access 2000 SR-1.
    Charlotte

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

    Re: Locking a subform

    If for instance the sort order of the form has been changed, Access sees this as a change in the design of the form and will save it (silently, without asking for confirmaton) upon closing, together with all subforms.

    You can avoid this by putting a command button on the main form to close it without saving. The OnClick event handler for this command button can look like this:

    Private Sub cmdClose_Click()
    DoCmd.Close acForm, Me.Name, acSaveNo
    End Sub

    If you want to prevent the user from closing the form any other way, do a search for "prevent close" in this forum. You'll find several ways to do this, for instance in <post#=166577>post 166577</post#>, but there are many others.

  10. #10
    New Lounger
    Join Date
    Aug 2002
    Location
    Chicago, IL, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking a subform

    The problem is that when I open the main form the next time, without specifiying the acFormReadOnly in code, that the subforms are NOT editable. After opening the main form the first time in read-only mode all the subforms get saved with their Allow... properties set to False. When the main form is reopened in edit mode (acFormEdit) the subforms Allow... properties are still False which prevents any editing in the subforms.

  11. #11
    New Lounger
    Join Date
    Aug 2002
    Location
    Chicago, IL, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Locking a subform

    Thanks for the tip on saving, but I'm still puzzled. With my problem, the main form is NOT getting saved, just some of the subforms. I have five subforms on the form and one of the subforms has a subform within it. When I close the main form four of the first level subforms get resaved, including the one with the nested subform. The nested, or 2nd level, subform is not resaved and one of the other first level subforms is not resaved. In addition to causing a time-consuming close process, when the main form has been opened using the acFormReadOnly constant with DoCmd.OpenForm the four first level subforms get saved with their AllowEdits, AllowAdditions, and AllowDeletions properties set to False. When I subsequently open the main form with acFormEdit the four subforms are NOT editable, i.e., their Allow.. properties are still set to False.

Posting Permissions

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