How to run make table query on an active table used by a form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dpatel1682
    New Member
    • Jul 2010
    • 35

    #31
    Subform/Datasheet is bound to tableB (which is created by a crosstab query) and TableA is being updated using VBA sqlstring. Is there any way I can close the form once I close it, I recreate the table? I tried doing that using docmd.close and docmd.open method but when I try to run the macro which recreates the TableB, it gives me the error mentioned before. Any way to clear the MS Access memoro / unlock that table?

    Thanks a lot for your help

    Comment

    • dpatel1682
      New Member
      • Jul 2010
      • 35

      #32
      Subform/Datasheet is bound to tableB (which is created by a crosstab query) and TableA is being updated using VBA sqlstring. Is there any way I can close the form once I close it, I recreate the table? I tried doing that using docmd.close and docmd.open method but when I try to run the macro which recreates the TableB, it gives me the error mentioned before. Any way to clear the MS Access memoro / unlock that table?

      Thanks a lot for your help.

      Comment

      • dsatino
        Contributor
        • May 2010
        • 393

        #33
        Memory really doesn't have anything to do with it. More than likely the error is caused because your code is in the form module and if you think about, the form really isn't closed if you're running code out of it. And if the form is n't closed, then anything bound to it will be locked.

        Mainly I think you need to realize that the error is caused by the fact that you're trying to operate outside of a 'best-practice'. I'm sure there are ways around it, but if this is a sizeable table then you're bloating you're database everytime you do this and causing the DB to creep ever closer to it's size limit for the sake of adding one record. This affect will grow with every record. You'll also preclude this form from ever being used in a multi-user environment.

        There are usually several ways to code something, some better than others and it's ok if you get it working with a less desirable method. But sometimes there's a case where the method is just the wrong way, even if you can get it to work. This is one of those cases.

        Comment

        • dpatel1682
          New Member
          • Jul 2010
          • 35

          #34
          My table is really small ~4000 records and I am updating everytime user click refresh button. Any other way to do this by staying in the same form? I know I can have another form pop up for the update and once it gets updated I can display the result in the 1st form via query as a source of that datasheet. But I do want to avoid going into another form for the updates

          Comment

          • dsatino
            Contributor
            • May 2010
            • 393

            #35
            Without seeing it directly, I can't really say what to do. Attached is a DB that has what I think you are trying to do.

            Open the form called "TestForm_wSubf orm". The main form is bound to a table in which you can add new records. The subform is based on a crosstab QUERY that will update when you click on the button.

            They're linked on the Branch field so you'll have to use a preexisting branch number to see it work
            Attached Files

            Comment

            • dpatel1682
              New Member
              • Jul 2010
              • 35

              #36
              Here's the db that I have with truncated data. Please let me know if I can explain it to you futher

              Comment

              • dsatino
                Contributor
                • May 2010
                • 393

                #37
                Sorry, I only have Access 2003 so I can't view this. You may be able to convert it though on your end and resend.

                Comment

                • dpatel1682
                  New Member
                  • Jul 2010
                  • 35

                  #38
                  Here you go. Thank you so much for your help

                  Comment

                  • dsatino
                    Contributor
                    • May 2010
                    • 393

                    #39
                    What parts of the form is the user updating specifically

                    Comment

                    • dpatel1682
                      New Member
                      • Jul 2010
                      • 35

                      #40
                      last subform with 2 lines

                      Comment

                      • dsatino
                        Contributor
                        • May 2010
                        • 393

                        #41
                        Oh boy. I'm not sure you fully understand what you're getting yourself into here.

                        From the looks of it, you're trying to build an accounting database from scratch. That would beg the question as to why? You can just buy those in the box and many of them can be accessed via a program like access if you need deeper analysis.

                        All that aside, your underlying tables are not normalized nor do they appear to be referential. You have no primary keys.

                        Now for the form. It appears that you didn't really plan it out, but just started building and now you've finally gotten to a point where you can't get something to work and rather than stepping back and reassessing what you've got, you're just trying jam it through. Basically you want to allow the user to directly update the summary data which fires a process that edits the detail which requires the users view to be deleted and remade. Your allowing the user to edit the results directly but making the program run in circles.

                        Believe me, my programming knowledge is all self-taught so I've been down the road you're trying to follow. Do yourself a huge favor and do some research on the fundamentals of databases, vba, and SQL.

                        Your SQL, as it is, will update every record that matches the account number criteria. So if change the Name of PSTest, your SQL is also going to change the name of TES. Now you've got two identical accounts in your account table and all your results will double. Be careful with SQL. You can write a lot of things that will return unintended results.

                        Also, you'll need a decent amount of VBA if you're column headings are going to change every six months. Otherwise you'll never acheive full automation and you'll be constantly updating anything that references the current dates that you're using.

                        Comment

                        • dpatel1682
                          New Member
                          • Jul 2010
                          • 35

                          #42
                          I agree with you comments regarding doing everything against the standard ways. I had PK and referentials before I received the data and when I looked at the data, I was forced to kill all the PK and Referentials. After reviewing the DB, is there any way to achive what I am trying to do on the same form?

                          Please advise

                          Thanks

                          Comment

                          • dsatino
                            Contributor
                            • May 2010
                            • 393

                            #43
                            Anything is possible, but in your case it's going to be difficult.

                            Your original problem/error is caused by the fact that your form is bound to the table you're trying to delete. You've closed the form visually, but since your code is in this form, the form is still open and hence the table is locked by the form.

                            What makes your problem difficult to solve is the fact that your process is circular and has no end point.

                            Table A
                            Feeds xTab Query
                            Makes Table B
                            Bound to Form
                            Edits to Form change Table B
                            Which calls process to update
                            Table A
                            ...

                            Start by getting your update procedure out of Form and into it's own module. Once you do that, find a way to call the process without the form being open and it'll probably work.

                            Comment

                            • dpatel1682
                              New Member
                              • Jul 2010
                              • 35

                              #44
                              I am kind of unsure in what do you mean by "Start by getting your update procedure out of Form and into it's own module. Once you do that, find a way to call the process without the form being open and it'll probably work"

                              Thanks a lot for your help

                              Comment

                              • dsatino
                                Contributor
                                • May 2010
                                • 393

                                #45
                                All of your code is behind forms(CBF). There's nothing inherently wrong with that, but in this case it needs to be outside the form in it's own module.

                                More specifically:

                                User updates data in your form
                                This fires the controls After_Update procedure which tries to run the code you wrote.
                                The code is failing because the table you're trying to update is bound to the form that is running the code.

                                If you put this update procedure in it's own module, you can close the form and call the procedure. This will probably allow you to do what you want.

                                Comment

                                Working...