How to set a form's/subform's "Allow Edits" property?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sueb
    Contributor
    • Apr 2010
    • 379

    How to set a form's/subform's "Allow Edits" property?

    I have a form/subform combination that I sometimes want to open disallowing Edits, Additions, and Deletions, depending on which password-protected menu option I'm coming from. (My menu structure is pretty simple, so I'm not using a switchboard, but rather some forms with controls on them.)

    How do I manipulate those properties, of both the form and its subform, (in the little procedure that checks the password) before I open the form?
  • beacon
    Contributor
    • Aug 2007
    • 579

    #2
    Check out this link: http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx

    It shows you how to access the the AllowEdits property in VBA. There are additional links and instruction for the other Allow-type properties.

    Comment

    • sueb
      Contributor
      • Apr 2010
      • 379

      #3
      That is a very helpful article. But I don't have the syntax correct for opening a form with its RecordsetType set to Snapshot. What I'm trying gives me a 'type mismatch':

      Code:
          Dim stDocName As String
          Dim stLinkCriteria As String
      
          stDocName = "Patient_IUR_Overview"
          
          ' Disallow Edits, Additions, and Deletions in both the Overview and Abbreviated forms
          DoCmd.OpenForm stDocName, , , , RecordsetType = Snapshot, stLinkCriteria

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Code:
        Dim strPassword As String
        
        'sueb will be able to Edit the Main Form (Orders) but NOT
        'the SubForm (Orders SubForm)
        strPassword = "sueb"
        
        Select Case strPassword
          Case "Admininstrator"                             'Allow Main/SubForm Edits
            Me.AllowEdits = True
            Me![Orders SubForm].Form.AllowEdits = True
          Case "sueb", "ADezii", "YaDa"                     'Allow Main Form Edits only
            Me.AllowEdits = True
            Me![Orders SubForm].Form.AllowEdits = False
          Case "John", "Harry", "Peter", "Paul", "Mary"     'SubForm only
            Me.AllowEdits = False
            Me![Orders SubForm].Form.AllowEdits = True
        End Select

        Comment

        • sueb
          Contributor
          • Apr 2010
          • 379

          #5
          Oh, that's nice and tidy, ADezii, and I'm going to save it in my code treasure box.

          However, currently my users don't sign in individually, and I'm trying a little different approach. My main menu offers three choices. Two of the choices share some forms in common, except that one choice allows you to edit the data and the other doesn't. I have a global constant ("ReadOnly") that the choices set appropriately, and the shared forms, in their "On Open" events, check that constant to see whether they should set their RecordsetType to "Snapshot" or not.

          All the forms are working fine except for the subform on one of the forms. I can't seem to touch it properly. Here's how the main form behaves "On Open" (I got this from the link provided by beacon):

          Code:
          Private Sub Form_Open(Cancel As Integer)
              Const conSnapshot = 2
              If ReadOnly Then
                  Forms!Patient_IUR_Overview.RecordsetType = conSnapshot
              End If
          End Sub
          but similar code in the subform's "On Open" event tells me that it can't find the form ("run-time error 2450"). I tried putting this code in "On Load" (what is the difference, anyway?), and tried referencing the subform within the main form's "On Open" event, all to no avail.

          Comment

          • sueb
            Contributor
            • Apr 2010
            • 379

            #6
            Any other ideas about how I can get this subform to set its RecordsetType when I open its parent form?

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              I cannot understand why the following Code will not work:
              Code:
              Private Sub Form_Open(Cancel As Integer)
                'Set the RecordsetType of SubForm to Snapshot
                Me![<SubForm_Name>].Form.RecordsetType = 2
              End Sub

              Comment

              • sueb
                Contributor
                • Apr 2010
                • 379

                #8
                I know I'm being completely dense about this, but I've tried a number of permutations of syntax (as you'll see in the following code, which contains only a fraction of them), and I just can't get this to stop saying it can't find either the subform (IURs_Abbreviat e_subform) or the main form (Patient_IUR_Ov er). This code is in the subform; is it supposed to be in the main form or something? That seems weird to me, since the main form has no problem setting its own RecordsetType OnOpen.

                Code:
                Private Sub Form_Open(Cancel As Integer)
                    If ReadOnly Then
                        'Forms!Patient_IUR_Overview!IURs_Abbreviated_subform.RecordsetType = conSnapshot
                        'Forms![Patient_IUR_Overview]![IURs_Abbreviated_subform].Form.RecordsetType = conSnapshot
                        'Forms![Patient_IUR_Overview].[IURs_Abbreviated_subform].Form.RecordsetType = conSnapshot
                        Me![IURs_Abbreviated_subform].Form.RecordsetType = conSnapshot
                    Else
                        'Forms!Patient_IUR_Overview!IURs_Abbreviated_subform.RecordsetType = conDynaset
                        'Forms![Patient_IUR_Overview]![IURs_Abbreviated_subform].Form.RecordsetType = conDynaset
                        'Forms![Patient_IUR_Overview].[IURs_Abbreviated_subform].Form.RecordsetType = conDynaset
                        Me![IURs_Abbreviated_subform].Form.RecordsetType = conDynaset
                    End If
                End Sub

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Can you Upload a Scaled Down Version of the DB? It has to be something relatively simple.

                  Comment

                  • sueb
                    Contributor
                    • Apr 2010
                    • 379

                    #10
                    Yes, ADezii, I'll do that tomorrow when I get back to work. Thanks!

                    And I'm sure you're right: it's got to be something simple that I'm just overlooking.

                    Comment

                    • sueb
                      Contributor
                      • Apr 2010
                      • 379

                      #11
                      Here's a zip of my front end and a scrap of the back end. As you can see, I've moved from thinking about the AllowEdits, etc., properties to just trying to set the form's RecordsetType to Snapshot and Dynaset, as appropriate.

                      Thanks so much for all your help.
                      Attached Files

                      Comment

                      • ADezii
                        Recognized Expert Expert
                        • Apr 2006
                        • 8834

                        #12
                        @sueb - It appears as though you were referring to the Source Object of the Sub-Form Control, instead of the Form Property of the Sub-Form Control itself. The Name of the Sub-Form Control is IURs1, while the Name of the Source Object for IURs1 is IURs_Abbreviate d_subform. Try:
                        Code:
                        Private Sub Form_Open(Cancel As Integer)
                        Const conSNAPSHOT As Byte = 2
                        Const conDYNASET As Byte = 0
                        
                        If ReadOnly Then
                          Me![IURs1].Form.RecordsetType = conSNAPSHOT
                        Else
                          Me![IURs1].Form.RecordsetType = conDYNASET
                        End If
                        End Sub

                        Comment

                        • sueb
                          Contributor
                          • Apr 2010
                          • 379

                          #13
                          I had actually previously noticed the name "IURs1" floating around (and wondered exactly when/where it was being created), and tried a stab at addressing it, but was certain I wasn't doing it correctly.

                          However, the lines you've given me don't seem to work either. I get an error (this time it's 2465) complaining that "Pre-Admitting IURs can't find the field 'IURs1' referred to in your expression."

                          I put this in the OnOpen event for the subform; was that right? (The constants are used by several forms, so they are declared publicly.)

                          Code:
                          Private Sub Form_Open(Cancel As Integer)
                              If ReadOnly Then
                                  Me![IURs1].Form.RecordsetType = conSnapshot
                              Else
                                  Me![IURs1].Form.RecordsetType = conDynaset
                              End If
                          End Sub

                          Comment

                          • ADezii
                            Recognized Expert Expert
                            • Apr 2006
                            • 8834

                            #14
                            I placed the following Code in the Open() Event of Patient_IUR_Ove rview, and it works fine:
                            Code:
                            Private Sub Form_Open(Cancel As Integer)
                              If ReadOnly Then
                                Me![IURs1].Form.RecordsetType = conSnapshot
                              Else
                                Me![IURs1].Form.RecordsetType = conDynaset
                              End If
                            End Sub

                            Comment

                            • sueb
                              Contributor
                              • Apr 2010
                              • 379

                              #15
                              AH! I did have it in the wrong OnOpen! Thanks so much for your patience, ADezii--it works great now!

                              I really need a reference that lays out neatly Access' contextual structure. There's so much that I'm unclear on (and I'm usually pretty good about this kind of thing--I just have nothing to even start with!)

                              Thanks again!

                              Comment

                              Working...