Auto Increment ID field of Linked table when entering on Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Catalyst159
    New Member
    • Sep 2007
    • 111

    #16
    Anyone have any Ideas on how to accomplish this.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #17
      Yes, basically what I laid out before. Use the BeforeInsert event of the form to populate the ProblemID. Use the DMax() function to get the last ID and add one to it. The DMax() syntax is in post #10.

      Comment

      • Catalyst159
        New Member
        • Sep 2007
        • 111

        #18
        The problem is that I only want to use the DMax() when I use the 'cmdNewItem' button to open the "Problem Records Detail" form for adding a new record.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #19
          Adding a new record triggers the BeforeInsert event.

          Comment

          • Catalyst159
            New Member
            • Sep 2007
            • 111

            #20
            So it should work then right ?

            Comment

            • Catalyst159
              New Member
              • Sep 2007
              • 111

              #21
              But when I click the ID in the "Problem Records List" Form, it will also bring up that record in the "Problem Records Detail" form. Will this be problematic in that case?

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #22
                Yes it will work. No it won't be a problem.

                Comment

                • Catalyst159
                  New Member
                  • Sep 2007
                  • 111

                  #23
                  I am still a little confused with the syntax. Is something like the following ok:

                  Code:
                  DMax("ID", "dbo_problems", "ProblemID = ID +1")

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #24
                    More like
                    Code:
                    DMax("ID", "dbo_problems") + 1
                    There's no need to specify which ID because it doesn't matter. You just want the max.

                    Comment

                    • Catalyst159
                      New Member
                      • Sep 2007
                      • 111

                      #25
                      Ok, let me try that. This should then populate the ID textbox on the "Problem Records Detail" form?

                      Comment

                      • Rabbit
                        Recognized Expert MVP
                        • Jan 2007
                        • 12517

                        #26
                        By itself? No. That only gets the value, you have to assign it to the control you want that value to go into.

                        Comment

                        • Catalyst159
                          New Member
                          • Sep 2007
                          • 111

                          #27
                          How can I test that
                          Code:
                          DMax("ID", "dbo_problems") + 1
                          is getting the correct value using the Immediate Pane to test it?

                          Comment

                          • Catalyst159
                            New Member
                            • Sep 2007
                            • 111

                            #28
                            How can I assign it to the control you want that value to go into?

                            Comment

                            • Catalyst159
                              New Member
                              • Sep 2007
                              • 111

                              #29
                              To Test in immediate window I used:

                              Code:
                              ? DMax("[ID]", "dbo_problems") + 1
                              This does work.

                              How can I assign this to the control on the form that I want the value to go into though?

                              Comment

                              • ChrisPadgham
                                New Member
                                • Jan 2012
                                • 11

                                #30
                                Code:
                                Me.ID = DMax("[ID]","dbo_problems") + 1
                                If you are in a multiuser environment you may like to do a save of the record immediately after this to prevent two users obtaining the same record id
                                Last edited by NeoPa; Jan 24 '12, 11:57 PM. Reason: Added mandatory [CODE] tags

                                Comment

                                Working...