473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

I am trying to re-create the existing table once it gets updated via form. However, I am getting error "The database engine could not lock table "tbl_test" because it is already used by another person or process".

Please help me find a way to get around this

Thanks
Aug 2 '10 #1

✓ answered by dsatino

Clear the on click event from the button and paste this into it:

Expand|Select|Wrap|Line Numbers
  1. Me.tbl_Raw_Data_by_Account_subform.Form.RecordSource = ""
  2. DoCmd.RunMacro "mcr_mktbl_Raw_Data_by_Account"
  3. Me.tbl_Raw_Data_by_Account_subform.Form.RecordSource = "tbl_Raw_Data_by_Account"
  4. Me.Refresh
  5. Me.Requery
It will get you buy the error, but this is really frowned upon.

49 5920
NeoPa
32,556 Expert Mod 16PB
Access has been specifically designed to stop you getting around this, for your own good. Consider what would happen when the operator of the form found that it suddenly crashed due to the record source disappearing.

I suggest you take a step back and consider what you actually want, then look at finding a sensible way to implement that.
Aug 2 '10 #2
@NeoPa
NeoPa,

Once user inputs the data via form, I want to close that form, run the make table query and open the form again but I am getting the "The database engine could not lock table "tbl_test" because it is already used by another person or process" error. Can you please suggest a way around?

Thanks
Aug 2 '10 #3
dsatino
393 256MB
Why are you remaking a table that you just added data too? Sounds, in general, like you're trying to an easy task the hard way.
Aug 2 '10 #4
@dsatino
that table is a crosstab query off of the source table which gets updated via form. I am having a groupby/sum issue which takes place in crosstab query. Therefore, I need to re-create that table.

Please advise

Thanks
Aug 2 '10 #5
dsatino
393 256MB
Ok then the next question is why are you making a table when you already have a query that will give you the same data without taking up memory?

Sorry for the questions, just pieces of the puzzle...
Aug 2 '10 #6
@dsatino
Because data is not in a crosstab format so I have to create that table first and then have users update the data in a newly created crosstab table via form.
Aug 2 '10 #7
NeoPa
32,556 Expert Mod 16PB
dpatel1682: Can you please suggest a way around?
Please refer to my earlier post for an answer to that question.

Luckily for you, it seems that Dsatino is leading you towards something that does make sense. I suggest you grab this opportunity with both hands. What he says makes sense.
Aug 2 '10 #8
dsatino
393 256MB
So your oder of ops goes like this?:

1. User inputs to form
2. Form updates some table (non-crosstab)
3. Form closes
4. Make-table query makes a crosstab table based on a crosstab query
5. Form re-opens
Aug 2 '10 #9
@dsatino
I did that and that's when I am getting an error "The database engine could not lock table "tbl_test" because it is already used by another person or process".

Thanks
Aug 2 '10 #10
dsatino
393 256MB
@dpatel1682
Ok, I was actually asking you if this is the order you are using. By your response I'm assuming that it is.

The next question is what is the crosstab table being used for?
Aug 2 '10 #11
@dsatino
Crosstab table is being used to sum the data based on the period field. In other words, it display the data in summarized manner
Aug 2 '10 #12
dsatino
393 256MB
Yes, but display it where? A form, report...
Aug 2 '10 #13
@dsatino
it display it in the form and row source is that table which is created from crosstab query. User update that form and after update it updates the value in source tables
Aug 2 '10 #14
NeoPa
32,556 Expert Mod 16PB
dpatel1682: User update that form and after update it updates the value in source tables
You've seen that happen? I'm surprised. I would not expect any updates to be possible on a form bound to a CrossTab query. The query wouldn't be updatable.
Aug 2 '10 #15
dsatino
393 256MB
So the same form takes the user input and displays the crosstab data?
Aug 2 '10 #16
@NeoPa
NeoPa,

Form is bound to a table which is created by that crosstab query which gets updated in the process with the source table which creates that crosstab table. Having said that, I need re-create that crosstab table since the source table was updated via form.

Relationship defined:

1. TableA(SourceTable)
2. QryA(CrosstabQuery) that gets data from TableA
3. TableB(CrosstabTable) that gets data from QryA
4. FormA that has TableB as source
5. Edits to FormA updates TableA - This will require me to re run the QryA which creates TableB

Hope I made myself clear and Thank you all very much for your help
Aug 2 '10 #17
@dsatino
Yes, same form takes the user input and displays the crosstab data.

Here's the steps defined to make this more clear

Relationship defined:

1. TableA(SourceTable)
2. QryA(CrosstabQuery) that gets data from TableA
3. TableB(CrosstabTable) that gets data from QryA
4. FormA that has TableB as source
5. Edits to FormA updates TableA - This will require me to re run the QryA which creates TableB


Thank you all very much for your help
Aug 2 '10 #18
dsatino
393 256MB
Is there any way you can zip the file and attach it?
Aug 2 '10 #19
I am sorry I can't send the file. Is there any other way that I can explain myself better

Thanks a lot for your help
Aug 2 '10 #20
@dsatino
I am sorry I can't send the file. Is there any other way that I can explain myself better

Thanks a lot for your help
Aug 2 '10 #21
dsatino
393 256MB
How about a screen shot of 'FormA' that might help me see the gist of what you're doing
Aug 2 '10 #22
NeoPa
32,556 Expert Mod 16PB
dpatel1682:
4. FormA that has TableB as source
5. Edits to FormA updates TableA - This will require me to re run the QryA which creates TableB
How can step 5 talk about updating TableA when step 4 indicates FormA is bound to TableB?
Aug 2 '10 #23
@NeoPa
NeoPa,

I am running vba afterupdate event when FormA gets updated, based on the account # it updates TableA.

Hope this makes sense.

Thanks
Aug 2 '10 #24
@dsatino
FormA is a datasheet which filters the databased on the user selection from the listboxes above
Aug 2 '10 #25
@dpatel1682
Screenshot attached in the main post
Aug 2 '10 #26
@dsatino
Here you go
Attached Files
File Type: zip ScreenShot.zip (98.4 KB, 121 views)
Aug 2 '10 #27
dsatino
393 256MB
Is this a form with a subform?
Aug 3 '10 #28
dsatino
393 256MB
I'm guessing at what's going behind this form which I think is either:
a main form bound to tableA and subform bound to tableB
or
the form is bound to tableB and edits via the form are in unbound controls that update tableA

Either way, constantly remaking the table is not good form. I can't remember the last time I bound a form to a crosstab, but I think the following is generally what you need to do:

The form can be bound to the crosstab query in the same manner that it can be bound to the table. Instead of remaking a table you can simply bind your form to the query and use the .Requery method. For a crosstab, the best way to do this is to go into the query properties and set the column names, but since you're pivoting on dates I'd assume they are variable. In this case you'll need some VBA in which you open a recordset based on the crosstab and use the field index to name the columns before you requery.


There may be some rust in there, but hopefully it will point you in the right direction. As NeoPa first stated, you don't want to remove the forms recordsource.
Aug 3 '10 #29
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
Aug 3 '10 #30
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
Aug 3 '10 #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.
Aug 3 '10 #32
dsatino
393 256MB
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.
Aug 3 '10 #33
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
Aug 3 '10 #34
dsatino
393 256MB
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_wSubform". 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
File Type: zip Test.zip (53.8 KB, 105 views)
Aug 3 '10 #35
Here's the db that I have with truncated data. Please let me know if I can explain it to you futher
Aug 3 '10 #36
dsatino
393 256MB
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.
Aug 3 '10 #37
Here you go. Thank you so much for your help
Aug 3 '10 #38
dsatino
393 256MB
What parts of the form is the user updating specifically
Aug 3 '10 #39
last subform with 2 lines
Aug 3 '10 #40
dsatino
393 256MB
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.
Aug 3 '10 #41
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
Aug 5 '10 #42
dsatino
393 256MB
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.
Aug 5 '10 #43
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
Aug 5 '10 #44
dsatino
393 256MB
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.
Aug 5 '10 #45
Can you please provide an example? I am still bit lost as to how do I do this. What I tried to do after the update is click on the "Refresh" button which will close the form, run the make table qry, and re open the form. Should I put the above steps in module and run that module on click ?
Aug 5 '10 #46
dsatino
393 256MB
Yes, move all the code from the click event(except the form close command) into a module.

On_Click close the form
In the forms on_close event, call the procedure that you moved to the new module.

I think this will work, but I've never tried it
Aug 5 '10 #47
ok I tried that but it didn't work. I created a module with a function called mktbl which had maketable qry followed by open form command. It gave me the same error when it tries to execute maketable qry

Any other idea?

Thanks for your help
Aug 5 '10 #48
dsatino
393 256MB
Clear the on click event from the button and paste this into it:

Expand|Select|Wrap|Line Numbers
  1. Me.tbl_Raw_Data_by_Account_subform.Form.RecordSource = ""
  2. DoCmd.RunMacro "mcr_mktbl_Raw_Data_by_Account"
  3. Me.tbl_Raw_Data_by_Account_subform.Form.RecordSource = "tbl_Raw_Data_by_Account"
  4. Me.Refresh
  5. Me.Requery
It will get you buy the error, but this is really frowned upon.
Aug 5 '10 #49
It worked. I used the following Code

Expand|Select|Wrap|Line Numbers
  1. tbl_Raw_Data_by_Account_subform.Form.RecordSource = ""
  2.  
  3. DoCmd.RunMacro "mcr_mktbl_Raw_Data_by_Account"
  4.  
  5. tbl_Raw_Data_by_Account_subform.Form.RecordSource = "tbl_Raw_Data_by_Account"
  6.  
  7. tbl_Raw_Data_by_Account_subform.Form.Refresh
  8.  
  9. tbl_Raw_Data_by_Account_subform.Form.Refresh
Aug 5 '10 #50

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the...
4
by: Oreo Bomb | last post by:
I have a secured database that contains a Read-Only group. This group has permissions to view reports, but cannot add, edit, or delete any DB objects. One of the reports the group needs access to...
4
by: DebbieG | last post by:
I have a form based on this query: SELECT Students.LastSerDT, OtherInfo.Served, OtherInfo.HSGradYr, OtherInfo.ActivePart, OtherInfo.Served, Students.SSN, & ", " & & " " & AS Name,...
1
by: bmoos1 | last post by:
I have a form that when the monthly payment is entered, it calculates the annual payment. The correct numbers appear in the form, but they are not in the table or query from which the form was...
2
by: Doc | last post by:
Per earlier post, I am trying to save 'out' production data from a program called Solomon - basically (I think) this was /is an Access/Sql based program. We are updating to different application...
0
by: The Frog | last post by:
Hello Everyone, I have been asked to try and create a single SQL query to retrieve product information from a database. The way that data is arranged is that in some tables there are user...
2
by: sbitaxi | last post by:
I have a query that performs a simple sum, a running total essentially. I want to be able to use that in a calculation in a form but I can't seem to get it to display anything beyond #Name? ...
19
by: MNNovice | last post by:
I have a Form where there are various combo boxes. These combo boxes are used as references for the parameter of various fields in a query. A command button opens a query with the parameters...
2
by: Laurel | last post by:
I am completely new to access. I have a make-table query that combines data from two/more tables, asks for a criteria, deletes the old table and produces a new table every time under the same name....
6
by: Debbie Toney | last post by:
Access 2007 3 table query: Contact table, Event table, Payment table. Contact may have an Event but no Payment, a Payment but no Event, or an Event and Payment. My query is duplicating the Event...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.