Custom record navigation with "new record" option

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    Custom record navigation with "new record" option

    I have a form with two subforms. The main form contains customer information. The first subform contains all the company information related to the customer. The second subform just lists the company names and is used as a navigation form of sorts for the first subform. Clicking on a record in the navigation subform changes the record being viewed on the first subform. As part of the recordset of the navigation subform, I have a UNION query to add the "New Record" option so that I can just click on the "New" record to add a new company. My problem is that when I first create a customer record, my "New Record" option isn't shown. I have to close out of the main form, reopen it and then navigate to the customer's record before I have the "New Record" option available.

    I have tried all sorts of refresh/requery of the navigation subform both at the subform control level and inside the form (Me.Subform.Requ ery and Me.Subform.Form .Requery) and it doesn't make a difference.

    Any ideas?
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    Seth,

    If I understand you correctly, when you open this main form, your navigation subform has the "New Customer" option. But, when you click that option, and the new record shows up, the "New Customer" option disappears in the subform? Thus, you are unable to add new sequential customers?

    Does it make a difference if you add a new customer and then select a different customer? That is, once it's gone, it's gone--until you close the form and re-open it?

    Could you share the code that fire when you select a new customer? That might help us....

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #3
      It is the "New Company" option that doesn't appear, not "New Customer". Customers being part of the main form and the related companies part of the subforms. When I open the customers form, the code that runs just sends it to a new record automatically. What I would expect is that as soon as I save the new customer record, I would have the option to click the "New Company" option in the navigation subform so that I can enter a company for that new customer. I can just start typing in the first subform (the one with all the data), but once I have filled in that record, the navigation subform isn't updated, so I don't have the option to go to a new record to enter a second company. I have to close out of the customer main form and then reopen it, navigate to the customer that I had just entered, and then I have the "New Company" option.

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3662

        #4
        You mention that you've tried many refresh/requery methods.

        Have you tried, after updating the customer, refreshing the cusotmer data and then refershing the company subform?

        OR.... Simply clicking a button on the customer subform that takes you to a new company?

        I'd have to see it in action to really understand what is going on. But, i think your bottom line is that you want to be able to add a new company at the time of adding a new customer, correct?

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          I haven't tried refreshing the customer form via code. I did do a refresh using the button in the ribbon bar and that didn't do anything.

          And yes, your understanding of the "bottom line" is correct.

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            Seth, on the new record, you will have to call the related subform to requery after the record has been update.

            The refresh doesn't pull new records in, just changes to the current records.

            Refresh or requery data
            Refreshing records only updates the data that already exists in your datasheet or form. It does not reorder records, display new records, or remove deleted records and records that no longer meet specified criteria. To perform those tasks, you can requery the records. You can requery data manually, by using a macro, or by using code.
            If I have the relationships right we have
            Parent
            Child1 - call it brother
            Child2 - call it sister

            So, in the afterupdate event of frm_brother

            Code:
            If Me.Dirty Then Me.Dirty = False
            Me.Parent!frm_sister.Requery
            then comboxes on sister:
            Me.frm_Parent!f rm_Sister.Form! CBO_OnSister.Re query

            do this quite often... never have figured out why the comboboxes have to be forced separately, one would thin that the subform.requery would enough for all of the controls to requery too...

            I need a nap
            Last edited by zmbd; Sep 26 '14, 10:53 AM.

            Comment

            • Seth Schrock
              Recognized Expert Specialist
              • Dec 2010
              • 2965

              #7
              You do have the relationships correct. So what I'm currently doing is entering a parent record. When I click on the next tab (where brother and sister are), I save the parent record so that it generates the PK value (linked to Microsoft Azure currently, but had the same problem when I was linked to Access) and then requery sister. The problem is that sister still doesn't show my "New Record" text from the UNION query. I have tried both Me.frm_sister.R equery and Me.frm_sister.F orm.Requery. Neither work.

              I already have the After Update event on brother so that when I add a new record, it updates sister to have the complete list.
              Last edited by Seth Schrock; Sep 26 '14, 03:01 PM. Reason: Added more info

              Comment

              • zmbd
                Recognized Expert Moderator Expert
                • Mar 2012
                • 5501

                #8
                Did you happen to try the If Me.Dirty Then Me.Dirty = Fals trick in frm_brother? That was the key in one of my databases. For some reason, the record was being held up, I'm guessing record locking, and this did something to force the final record save.

                Comment

                • Seth Schrock
                  Recognized Expert Specialist
                  • Dec 2010
                  • 2965

                  #9
                  I use the DoCmd.RunComman d acCmdSaveRecord command without the IF to save the record when I do make changes. However, there would not have been any changes made to frm_brother, only to frm_Parent. So your code would return false.

                  Comment

                  • zmbd
                    Recognized Expert Moderator Expert
                    • Mar 2012
                    • 5501

                    #10
                    Most likely then a red-herring; would you humor me and stick it in? At worst nothing happens and to a chemist that information is just as valuable as having the expected happen too. The line can always be deleted out.

                    Comment

                    • Seth Schrock
                      Recognized Expert Specialist
                      • Dec 2010
                      • 2965

                      #11
                      I added it as well as a Debug.Print line to let me know if it ran and it never did.

                      Comment

                      • Rabbit
                        Recognized Expert MVP
                        • Jan 2007
                        • 12517

                        #12
                        What's the SQL for the data in your navigation subform?

                        Comment

                        • Seth Schrock
                          Recognized Expert Specialist
                          • Dec 2010
                          • 2965

                          #13
                          Code:
                          SELECT AcctInfoID_pk
                          , CustID_fk
                          , CompanyName
                          , CompanyID_pk 
                          FROM tblAcctInfo INNER JOIN tblCompany 
                          ON tblAcctInfo.CompanyID_fk = tblCompany.CompanyID_pk 
                          WHERE CompanyID_fk <> 1 
                          UNION 
                          SELECT 0
                          , 1
                          , '<<New>>' As CompanyName
                          , null 
                          FROM tblAcctInfo 
                          ORDER BY CompanyName DESC

                          Comment

                          • Rabbit
                            Recognized Expert MVP
                            • Jan 2007
                            • 12517

                            #14
                            Which field is the link between the main form and the navigation sub form?

                            Comment

                            • Seth Schrock
                              Recognized Expert Specialist
                              • Dec 2010
                              • 2965

                              #15
                              CustID_fk. Now that you mention that, I see why I am changing the recordsource of the navigation subform in the parent form's OnCurrent event to make the UNION part of the query have the correct value in the second field. I'll have to try to make that change when I save the new record in main form.

                              Comment

                              Working...