Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314

    Lock specific records at runtime in a form

    I have a table with a checkbox called Locked. I want to dynamically lock records in a form, when the checkbox is True. My form is a NavigationSubform, SCATeam. According to Access > Concepts > Reports > Set form, report, and control properties in code, one can set form properties at run-time in VBA code as follows:
    Forms!Customers.Visible = True



    I have tried to implement this in my application as indicated above, and I have tried using the NavigationSubform syntax, perhaps incorrectly, in place of "SCATeam", but all to no avail. Any Ideas how I make this work?
    Code:
    If [Locked] = True Then
              Forms!SCATeam.AllowAdditions = False
              Forms!SCATeam.AllowDeletions = False
              Forms!SCATeam.AllowEdits = False
    Else
              Forms!SCATeam.AllowAdditons = True
              Forms!SCATeam.AllowDeletions = False
              Forms!SCATeam.AllowEdits = True
    End If
    Last edited by WCStarks; 12-31-2018 at 11:47 AM. Reason: fix code formatting

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    I would simply use Me since presumably you'll be in that form's module:

    Me.AllowAdditions = False

    The logical place for your code is the current event of the subform.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    It is in the form's On Current event property, Public Sub Form_Current(). I had also tried that earlier. I just tried it again as suggested, so I could get the error message: "Compile error: Method or data member not found".
    Code:
    If [Locked] = True Then
         Me.AllowAdditions = False
         Me.AllowDeletions = False
         Me.AllowEdits = False
    Else
         Me.AllowAdditons = True
         Me.AllowDeletions = False
         Me.AllowEdits = True
    End If

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    On the first line? I'd also use Me on that:

    If Me.Locked = True Then

    and make sure that's a field on the form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    The If Statement works correctly as written. It does not error until it gets to one of the setting statements, in either case. I tried Me.[Locked], but get the same error in which ever case is run. [Locked] is not actually on the form, but it is available in the record source for the form. Notice the name of the form in the Public Sub Form_Current().

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Hmm. Can you attach the db here? Did you change the declaration, because by default it would be private:

    Private Sub Form_Current()
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    I don't believe I changed the declaration. Here is the whole On Current VBA
    Code:
    Public Sub Form_Current()
    If Not Me.NewRecord Then 'Get current dates for Joined and Resigned
        Me.Joined = ELookup("[Status_Date]", "Membership", "[Status] = ""Joined"" AND [Member_ID] =" & [ID], "[Status_Date] Desc")
        Me.Resigned = ELookup("[Status_Date]", "Membership", "([Status] = ""Resigned"" OR [Status] = ""Terminated"" or [Status] = ""Emeritus"" OR [Status] = ""Retired"") AND [Member_ID] =" & [ID], "[Status_Date] Desc")
        
        'If TabCtl0 = 1 Then 'Ledger Page Tab is Active
            If Me.[ID] = 34 Then 'SCATeam Ledger
                 Me.CtrLedger.SourceObject = "Team Trans Subform"
            Else 'Member Ledger
                 Me.CtrLedger.SourceObject = "Team Mem_Ledgers Subform"
            End If
        'End If
    End If
    If Me.[Locked] = True Then
         Me.AllowAdditions = False
         Me.AllowDeletions = False
         Me.AllowEdits = False
    Else
         Me.AllowAdditons = True
         Me.AllowDeletions = False
         Me.AllowEdits = True
    End If
    End Sub
    I will create another sanitized version of the db and send it when ready.

  8. #8
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Here is the db. When you first open the db, you will see the Members Navigation tab active with the members form displayed. The default record that displays is an empty record, the record I want to lock. Its locked field is checked. The note for this record explains its purpose. The On Current event, is for this Member Main form. The file name of the form is SCATeam.
    SCATeam Sanitized.zip

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Ah, I'm blind, didn't notice this one:

    Me.AllowAdditons = True

    should be "AllowAdditions".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Yes, we both were blind. That record is no longer editable, however, there is a bad side affect. I cannot select anyone from the combo in the header.

  11. #11
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    In the got focus event of the combo, set the allow edits property to true.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Thank you. That works. Now, please go to a different record from the empty record and see what happens during the update. Then go back to the empty record and see what happens. The screen flashes several times, when first moving from the empty record to another, or moving to the empty record from another. Once you are away from the empty record, and go from record to record, the updates flash less. This didn't happen before. Any Idea what is happening to cause the multiple updates?

  13. #13
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    It doesn't seem bad to me, but it's likely the ELookup()'s and setting the source object of the subform. Comment those lines out and see if you see the same flashin.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    WCStarks is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    314
    Thanks. I'll mark the post resolved.

  15. #15
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Were those the problem? Might be ways around if so. Particularly this one:

    If Me.[ID] = 34 Then

    Rather than set the source object every time, you could use a variable and only set it when the ID changes to/from 34.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 01-18-2016, 07:02 PM
  2. Replies: 2
    Last Post: 01-14-2015, 12:00 PM
  3. Replies: 15
    Last Post: 04-17-2012, 01:42 PM
  4. Specific records in a form
    By ellixer in forum Forms
    Replies: 1
    Last Post: 06-30-2011, 08:56 AM
  5. Filter specific records on sub form
    By foxtet in forum Forms
    Replies: 5
    Last Post: 06-05-2011, 12:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums