How to force a "new record write"

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

    #1

    How to force a "new record write"

    I have a form with a subform, and this subform allows the addition of a new child record using only a few essential fields. Typically, after entering these few fields, the user goes on to fill in the rest of the fields, and that action happens by clicking on a button that opens a separate form that displays all the fields for the new child record.

    The problem is that it doesn't. It displays the separate form, but on a blank record rather than the newly added record. If the user moves the cursor in the abbreviated form into a field for a different child record, and THEN clicks on the button, the separate form displays the newly added record.

    How can I force the child record to be written (probably, in the code for the "separate form" button)?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    You can force the Save of a Record in a Sub-Form by setting the Dirty Property of the Sub-Form Object itself to False. This, of course, will not stop Error Messages if Validation Rules, Input Masks, Required Property of any Control on the Sub-Form is violated prior to the Save. Substitute your Main Form and Sub-Form Names below in the following Code:
    Code:
    Forms![<Main Form>]![<Sub-Form>].Form.Dirty = False

    Comment

    • sueb
      Contributor
      • Apr 2010
      • 379

      #3
      I don't know what it is about this application's syntax that stumps me so, but I simply could not get this line to do anything other than give an error. Here is the whole module that's attached to the "go to the separate form" button:

      Code:
      Private Sub Open_IUR_Subform_Click()
      On Error GoTo Err_Open_IUR_Subform_Click
      
          Dim stDocName As String
          Dim stMainForm As String
          Dim stLinkCriteria As String
      
          stMainForm = "Patient_IUR_Overview"
          stSubForm = "IURs Abbreviated: subform"
          stDocName = "IURs: subform"
          
          'Forms![<stMainForm>]![<stSubForm>].Form.Dirty = False
          'Forms![stMainForm]![stSubForm].Form.Dirty = False
          'Forms![<stSubForm>]![<stDocName>].Form.Dirty = False
          'Forms![stSubForm]![stDocName].Form.Dirty = False
          
          stLinkCriteria = "[IURs.IUR Index]=" & Me![IUR Index]
          DoCmd.OpenForm stDocName, , , stLinkCriteria
      
      Exit_Open_IUR_Subform_Click:
          Exit Sub
      
      Err_Open_IUR_Subform_Click:
          MsgBox Err.Description
          Resume Exit_Open_IUR_Subform_Click
          
      End Sub
      The "OpenForm" thing works great; I just included it in the interest of completeness.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Use the Syntax that I showed you in Post# 2, namely:
        Code:
        Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False

        Comment

        • sueb
          Contributor
          • Apr 2010
          • 379

          #5
          Whether I use constants in that line, or whether I use the actual form names, I get the following error:

          "Pre-Admitting IURs can't find the form 'Patient_IUR_Ov erview' referred to in a macro expression or Visual Basic code."

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Where is Pre-Admitting IURs originating from?

            Comment

            • sueb
              Contributor
              • Apr 2010
              • 379

              #7
              That's the name of the database itself. I forget where that's set.

              Comment

              • sueb
                Contributor
                • Apr 2010
                • 379

                #8
                Anyone else have any ideas to help me with this?

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  The only thing that I can tell you, sueb, is that the Syntax below does work. I happen to have a copy of the DB that you sent me, and tested it again. The only thing that I can think of is that [Patient_IUR_Ove rview] is not Open when the Code is being executed. If the Back End has not changed, you can Upload the Front End and I'll take a look at it again.
                  Code:
                  Forms![Patient_IUR_Overview]![IURs Abbreviated: subform].Form.Dirty = False

                  Comment

                  • sueb
                    Contributor
                    • Apr 2010
                    • 379

                    #10
                    Oh, thanks, Adezii! Here's the front end.
                    Attached Files

                    Comment

                    • ADezii
                      Recognized Expert Expert
                      • Apr 2006
                      • 8834

                      #11
                      Have a Look/See:
                      Attached Files

                      Comment

                      • sueb
                        Contributor
                        • Apr 2010
                        • 379

                        #12
                        Gosh, I don't know, Adezii. I still get that same error. Even though the line you sent me was exactly the same as one I had tried before, I copied and pasted it out of your version, just to make sure, but to no avail.

                        This is really weird. Is there some "Access-level" setting that could be involved? I can't imagine what that would be, but this just isn't working in my copy.

                        Comment

                        • ADezii
                          Recognized Expert Expert
                          • Apr 2006
                          • 8834

                          #13
                          This is really weird. If you can, send me now the Copy that isn't working even though the Code chaqnges work on my end. Nothing has changed in the Back End, correct?

                          Comment

                          • sueb
                            Contributor
                            • Apr 2010
                            • 379

                            #14
                            Okay, here's both the front end and a safe back end. I surely appreciate your help with this!
                            Attached Files

                            Comment

                            • ADezii
                              Recognized Expert Expert
                              • Apr 2006
                              • 8834

                              #15
                              Give this a try, sueb.
                              Attached Files

                              Comment

                              Working...