473,406 Members | 2,954 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,406 software developers and data experts.

Recordset is locked for editing (DAO)

Hi,

I am using following code to select a recordset

Expand|Select|Wrap|Line Numbers
  1. Set rsI = CurrentDb.OpenRecordset("SELECT [Halvfabrikat].[IDArtikkel], [Halvfabrikat].[Hfnavn], [Halvfabrikat].[IDRåvare], " & _
  2. " qryTotalkostPerEnhetHF.Lønnskost, qryTotalkostPerEnhetHF.Råvarekost FROM Halvfabrikat INNER JOIN qryTotalkostPerEnhetHF" & _
  3. " ON Halvfabrikat.IDArtikkel = qryTotalkostPerEnhetHF.IDArtikkel WHERE Isnull(qryTotalkostPerEnhetHF.Lønnskost) = False AND" & _
  4. " Isnull(qryTotalkostPerEnhetHF.Råvarekost) = False")
Later on in the code, I want to edit data in the recordset

Expand|Select|Wrap|Line Numbers
  1.         IDRåvare = rsO!Artikkelnr
  2.         rsI.FindNext rsI!IDArtikkel = " & test & "
  3.         rsI.Edit
  4.         rsI!IDRåvare = IDRåvare
  5.         rsI.Update
When rsI.edit is reached, I get the error code 3027 "Cannot Update. Database or object is read-only"

Is it because I have used queries in the Select string?

The queries are partly "built" on the table halvfabrikat.

Any help is much appreciated :)

Martin
Jul 12 '10 #1

✓ answered by NeoPa

Reasons for a Query to be Non-Updatable.

I suggest you have a look through these as an early step. There is little point getting the code to work perfectly if you cannot find an updatable query to do what you need.

I'm sure DenBurt will guide you wisely anyway. He's very experienced.

23 4529
Denburt
1,356 Expert 1GB
@Martin Lang
A few questions what event are you using this code in?
I would also like to know if the table "Halvfabrikat" is used in the query built (if you built one) or if that is the table used in the forms Record Source property.
Jul 12 '10 #2
@Denburt
Hi Denburt,

Thank you for showing interest.

Table "halvfabrikat" is used in the query biult.

There is no form involved in the code. It is a kind of "Update" routine.

Martin
Jul 12 '10 #3
Here is the whole code if needed
Expand|Select|Wrap|Line Numbers
  1. Public Function fncOverføreHFtilråvare()
  2.  
  3. Dim rsI As DAO.Recordset
  4. Dim rsI2 As DAO.Recordset
  5. Dim rsI3 As DAO.Recordset
  6. Dim rsI4 As DAO.Recordset
  7. Dim rsO As DAO.Recordset
  8.  
  9. ' Select the unique IDArtikkel
  10. Set rsI = CurrentDb.OpenRecordset("SELECT [Halvfabrikat].[IDArtikkel], [Halvfabrikat].[Hfnavn], [Halvfabrikat].[IDRåvare], " & _
  11. " qryTotalkostPerEnhetHF.Lønnskost, qryTotalkostPerEnhetHF.Råvarekost FROM Halvfabrikat INNER JOIN qryTotalkostPerEnhetHF" & _
  12. " ON Halvfabrikat.IDArtikkel = qryTotalkostPerEnhetHF.IDArtikkel WHERE Isnull(qryTotalkostPerEnhetHF.Lønnskost) = False AND" & _
  13. " Isnull(qryTotalkostPerEnhetHF.Råvarekost) = False ")
  14. Set rsO = CurrentDb.OpenRecordset("råvare")
  15. Test = rsO.RecordCount
  16.  
  17. ' Loop to add one row for each IDArtikkel
  18. While Not rsI.EOF
  19.     Test = rsI!IDArtikkel
  20.     Set rsI2 = CurrentDb.OpenRecordset("Select Ingrediensliste From tblIngredienslisteHF WHERE IDartikkel = " & rsI!IDArtikkel & "")
  21.     Set rsI3 = CurrentDb.OpenRecordset("Select [sum av kj1], [sum av kcal1], [sum av fett1], [sum av protein1], [sum av karbohydrat1] FROM qryNæringsinnholdHalvfabrikataPåArtikkelnivå WHERE IDHalvfabrikat = " & rsI!IDArtikkel & "")
  22.     Set rsI4 = CurrentDb.OpenRecordset("Select totalenhetskost From qryTotalkostPerEnhetHF WHERE IDartikkel = " & rsI!IDArtikkel & "")
  23.     If IsNull(rsI!IDRåvare) = True Then
  24.         rsO.AddNew
  25.         rsO!Råvarenavn = rsI![Hfnavn]
  26.         rsO!Råvaredata = rsI2!Ingrediensliste
  27.         rsO!Kalkulasjonspris = rsI4!Totalenhetskost
  28.         rsO!Kj = rsI3![Sum Av KJ1]
  29.         rsO!kcal = rsI3![sum av kcal1]
  30.         rsO!Protein = rsI3![sum av protein1]
  31.         rsO!karbohydrat = rsI3![sum av karbohydrat1]
  32.         rsO!Fett = rsI3![sum av fett1]
  33.         rsO.Update
  34.         rsO.MoveLast
  35.         IDRåvare = rsO!Artikkelnr
  36.         rsI.FindFirst rsI!IDArtikkel = " & test & "
  37.         rsI.Edit
  38.         rsI!IDRåvare = IDRåvare
  39.         rsI.Update
  40.  
  41.     Else
  42.         Dim strwhere As String
  43.         strwhere = "[råvare].[Artikkelnr] =" & rsI!IDRåvare & ""
  44.         rsO.FindFirst strwhere
  45.         rsO.Edit
  46.             rsO!Råvarenavn = rsI![Hfnavn]
  47.             rsO!Råvaredata = rsI2!Ingrediensliste
  48.             rsO!Kalkulasjonspris = rsI4!Totalenhetskost
  49.             rsO!Kj = rsI3![Sum Av KJ1]
  50.             rsO!kcal = rsI3![sum av kcal1]
  51.             rsO!Protein = rsI3![sum av protein1]
  52.             rsO!karbohydrat = rsI3![sum av karbohydrat1]
  53.             rsO!Fett = rsI3![sum av fett1]
  54.             rsO.Update
  55.     End If
  56.     rsI.MoveNext
  57.  
  58.  
  59. Wend
  60. Set rsI = Nothing
  61. Set rsI2 = Nothing
  62. Set rsI3 = Nothing
  63. Set rsI4 = Nothing
  64. Set rsO = Nothing
  65.  
  66. End Function
Jul 12 '10 #4
Denburt
1,356 Expert 1GB
@Martin Lang
I am still unsure of how or where you are calling the function "fncOverføreHFtilråvare" from. If you are calling the function from inside of a query then you are definitely going to have problems.

I am not sure exactly what you are trying to do but I will try to help.

1.You will need a form with a button or something, or maybe a macro to call this function and that is where we need to start. Once you have that we can work from there.

2.Just for verification purposes create a new query don't use the wizard, cancel it if it shows up and if the "Show Table" dialog shows up close that also. Then you can use the menu view to go to SQL view.

Insert the SQL statement for rsI then view it as a datasheet and see if you can edit/add new records manually.


Let us know how that goes.
Jul 12 '10 #5
Thank you very much Denburt.

1. Hehe, of course. Didn't think of it in that way. I have a button that calls the macro.

2. Done. Couldn't edit anything.

Wow, you're good at problemshooting.

:)

Martin
Jul 12 '10 #6
Denburt
1,356 Expert 1GB
@Martin Lang
Glad I could help, if you have any trouble setting up the query so it is editable you can post your table structures (pointing out primary keys etc.) and I will be glad to see what I can do. So many time there are people that will not set a simple primary key or something similar and that can prevent a query from updating.

If you need help or would like more information on structuring your tables their primary keys and such then you can take a look at this article.
http://bytes.com/topic/access/insigh...ble-structures
Jul 12 '10 #7
Thank you,

I have had a small course in normalisation and table structures. Of course, I might have gone wrong on that part.

Here are the tables used (underlined is PK, *Field is foreign key)

1. tblhalvfabrikat (IDArtikkel, HFnavn, antall enheter per oppskrift, *IDAvdeling, Sist endret, IDråvare)
In English
1. tblIntermediates(IDArticle, Intermediatename, number of products per recipe, *IDDepartment, Last edited, IDIngredient)
(the last column, IDIngredient, is used for a macro that copies that specific intermediate to the ingredient table)

2. Råvare (IDRåvare, *VismaID, Råvarenavn, Navn i produktdeklarasjon, Forholdstall, Kalkulasjonspris, Kalkprissistendret, Kj, Kcal, Protein, Karbohydrat, Fett, Råvaredata)
In English
2. Ingredients (IDIngredient, *VismaID, Ingredientname, Name used for productdeclaration, Rationumber, Calculationprice, Calculationpricelastedited, Energy fat and so on, Ingredientdata)
3.tblHalvfabrikatoppskrift (*IDHalvfabrikat, *IDråvare, Mengde)
In English
3. tblIntermediaerecipe (*IDIntermediate, *IDIngredient, Amount)

I have attached a part of the database where you also may have a look on the tables, the four relevant queries that are used in the final qryTotalcostperIntermediate, in addition to the code.
Attached Files
File Type: zip Produktdatabase versjon 1.0.zip (54.6 KB, 126 views)
Jul 13 '10 #8
NeoPa
32,556 Expert Mod 16PB
Reasons for a Query to be Non-Updatable.

I suggest you have a look through these as an early step. There is little point getting the code to work perfectly if you cannot find an updatable query to do what you need.

I'm sure DenBurt will guide you wisely anyway. He's very experienced.
Jul 13 '10 #9
Thanks Neopa,

Will do. Hopefull I will be able to solve it myself with this article. Will let you know if I do :)

Martin
Jul 13 '10 #10
NeoPa
32,556 Expert Mod 16PB
You may well Martin. I have to say though, that knowing your SQL and coding that SQL into your string using VBA are two entirely different things. If you manage to get from A to B without need for further help then that'd be well done indeed.
Jul 13 '10 #11
@NeoPa
Well, I have found out what causes the locked query.

I have a query A with following fields
(*IDArticle, *IDIngredient, Amount, Ingredientpurchaseprice, Cost: Amount*Ingredientpurchaseprice)

Query B is used to summarize the field Cost. It is query B that causes problem.

If I remove "group by article" from query B, I am able to edit data in it. But on the other hand, I will need it later on....

The reason why is that the Select string in the DAO code is... Select IDArticle where Sum(Ingredientcost) is not null...

Maybe there is a way to work around the problem... or a solution in the SQL string?
Jul 13 '10 #12
Hmm, I have been thinking.... a lot... And to me the simplest solution seems to be to write the stuff I need from the query into a table, and use that table in my SQL string.... Unless you feel there is an easier way around this....
Jul 13 '10 #13
Denburt
1,356 Expert 1GB
@Martin Lang
I am still a bit confused but I will do my best...
If I remove "group by article" from query B, I am able to edit data in it. But on the other hand, I will need it later on....

The reason why is that the Select string in the DAO code is... Select IDArticle where Sum(Ingredientcost) is not null...

Maybe there is a way to work around the problem... or a solution in the SQL string?
Once you run query B then you can take the ID (IDArticle?) store it in a variable and rerun query B using the ID in a where statement to select that record without "group by article" and make your adjustments...?
Jul 13 '10 #14
@Denburt
Something like Dsum(Cost; qryCostPerEachIngredient; IDArticle = varIDArticle) ?

Well, that works, but it gives me multiple records. Then again, I could just use the "Select Distinct in the SQL string....?
Jul 13 '10 #15
Denburt
1,356 Expert 1GB
@Martin Lang
I am sorry you have me completely lost now. I read post #12 and you were referring to query A and query B and mentioning items not even in the database that you posted or in the code you have previously posted. The database you posted has one query that sums your figures up but it isn't used in the code either so excuse me if I am a little confused as to where we or you are currently and what your goal is at this point. Maybe you can rephrase your question and I will see if I can help.
Jul 13 '10 #16
NeoPa
32,556 Expert Mod 16PB
Martin,

I plan to look at this again this evening. Could you do me a favour and explain your current situation and question as clearly as you can and how it relates to the database attached. I will be able to look at that when I get home, but I haven't had a chance to yet as I'm at work.
Jul 13 '10 #17
Sorry that I haven't expressed this clearly enough :) I really appreciate your help and kind offers :) No reason to excuse yourself as it is me who complicates things with my badly defined problems :)

I used the terms query A and query B to simplify my Norwegian structure in English :) And your advice has really helped me to understand why the original error message appeared in the code I posted in #4.

If you have a look in post #4, on row 10, I have a Select string. The select string consist of several tables/queries. "Query B" was making the error. The reason why was that I had ticked "totals" in design view(if you understand what I mean, not sure if it is the correct translation to the English version of Access), but a new row pops up in design view) . "Totals" locks all posts for editing. That was why I couldn't run my original code (post #4), where I wanted to edit the DAO recordsource which query B locked.

I think I will be able to solve it by myself now. I will come back to you if not. Anyway I will let you know how it goes.

Thanks to both of you :) I really appreciate it!

Martin
Jul 13 '10 #18
Denburt
1,356 Expert 1GB
If you have a look in post #4, on row 10, I have a Select string. The select string consist of several tables/queries. "Query B" was making the error. The reason why was that I had ticked "totals" in design view(if you understand what I mean, not sure if it is the correct translation to the English version of Access), but a new row pops up in design view) . "Totals" locks all posts for editing. That was why I couldn't run my original code (post #4), where I wanted to edit the DAO recordsource which query B locked.
Ah I see it, you just need to open a recordset for "Select IDRåvare from Halvfabrikat where IDHalvfabrikat = " & rsI!IDArtikkel & "" then you can update IDRåvare instead of trying to update the RSI recordset since you can't update RSI for reasons specified earlier.

Good luck hope all goes well let us know if there is anything else we can do.
Jul 13 '10 #19
@Denburt
Thank you Denburt,

This is my first "real" database. A lot of lessons learned. My plan is to rebuild it at a later point when I am sufficiently motivated. Now, it is more about solutions that works and less the most optimal solutions.

So I went for a dummytablesolution where data is temporary stored. Will look deeper into this issue at a later point. Till then, hopefully these things have matured for me :)

Thank you for your friendly offer. I am so glad that people like you, Nico and NeoPa exists!

Have a nice evening, or maybe it is day where you are :)

Martin
Jul 13 '10 #20
Denburt
1,356 Expert 1GB
@Martin Lang
I am just glad I could help.

Everyone has to start somewhere, and I know I have had to stop and say wait I have an issue.... That's one reason I decided to help on this board the members were all so willing to help me whenever I have had or have an issue or two come up.

You have a good evening as well and again I am glad you have a working solution.
Jul 13 '10 #21
NeoPa
32,556 Expert Mod 16PB
Martin Lang: Sorry that I haven't expressed this clearly enough :) I really appreciate your help and kind offers :) No reason to excuse yourself as it is me who complicates things with my badly defined problems :)
That's probably a little harsh on yourself Martin. Defining problems clearly is a struggle for most people who speak English natively. Yours are always well explained and it's clear you have gone to some trouble to do that as well as you can. I was simply alluding to the fact that the later situation wasn't so clear related to the attached database. Easily done, and no longer a problem anyway.
Martin Lang: If you have a look in post #4, on row 10, I have a Select string. The select string consist of several tables/queries. "Query B" was making the error. The reason why was that I had ticked "totals" in design view(if you understand what I mean, not sure if it is the correct translation to the English version of Access), but a new row pops up in design view) . "Totals" locks all posts for editing. That was why I couldn't run my original code (post #4), where I wanted to edit the DAO recordsource which query B locked.
That makes perfect sense Martin. In SQL that translates to a GROUP BY clause (which is quite common). Now, when you see that phrase mentioned you'll know it's about using Totals in a query :)

By the way, I'm very pleased you have managed to get a solution, and please post more questions if you have them.
Jul 13 '10 #22
Denburt
1,356 Expert 1GB
@NeoPa
Very well put NeoPa! If only I could put things so eloquently. :)

Oh and Martin I wanted you to know I thought you explained things quite well by the way. Sometimes it can be difficult to get a point across no matter who we are or who we are talking to.
Jul 13 '10 #23
Well, that is good to hear. Thank you. I will definitely come back whenever I am struggling with a new problem. Take care both of you :)
Jul 14 '10 #24

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

Similar topics

4
by: MNC | last post by:
I'm using Access2002, and can't seem to get an updateable recordset going :-( What am I doing wrong, here's the code. The form's controls are not locked, the recordset type is Dynaset (changing...
4
by: JMCN | last post by:
object invalid or no longer set - confusion of the recordset in access 2003. i am currently converting from access 97 to access 2003. majority of the codes converted over perfectly fine, though...
2
by: Roger | last post by:
I've got an access97 app that is being converted to access2000 a dao recordset is different than an ado recordset, and whether or not the app works is determined by the priority of the libraries in...
8
by: aland | last post by:
Hi, I'm hoping someone can help me with this code. I'm getting a 'Type mismatch' error, and I'm not sure why. The SQL works fine in SQL view, so I'm not sure if that's the problem or not. This is...
2
by: ajspacemanspiff | last post by:
I currently have a solution that requires 2 sub queries, where each of them is convereted into a crosstab query and then I join the crosstab queries to a result. I would like to make this more...
6
by: ET | last post by:
Hi, I need help with run time errors. The application is running on Access 2002. It is recordset, loops the records from query, one by one row, in ADO it gives error 80040e21, invalid...
8
by: LabGeek | last post by:
Do I have to recreate a recordset everytime I want to use it, or can I simply create a recordset on the form open event and access it for the life of the form? I guess my question is really what...
4
by: darkforcesjedi | last post by:
Creating a connectionless recordset in ADO is simple enough, but how do you do it in DAO? I want a recordset stored in memory so I can filter/sort it easily. If I create a table I can make it work,...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.