|
-
Jun 9th, 2004, 09:48 AM
#1
Thread Starter
New Member
read only problem RESOLVED
I have an Access db with 4 tables in it which I'm accessing through vb (customers, jobs, quotes and invoices).
I can access the customer table ok.
The db has a query which links 3 tables together but when I try to add a new record to it using
datJobs.recordset.addnew I get an error message
"Run-time error 3027
Cannot update database or object is read only."
The db isn't read only as I can access the customers table and make changes.
The read only property on the data object is also set to false.
Any help would be appreciated
Last edited by peter piper; Jun 16th, 2004 at 03:51 PM.
-
Jun 9th, 2004, 09:54 AM
#2
PowerPoster
Sometimes I have inadvertantly opened my recordsets as Read-Only. You might check that sort of theing.
-
Jun 9th, 2004, 10:10 AM
#3
Post the code you're using to open the DB and save to it.
What is datJobs?
-
Jun 9th, 2004, 11:53 AM
#4
Thread Starter
New Member
datJobs is the name of the data object
the code used is
Private Sub cmdNew_Click()
datJobs.Recordset.AddNew
End Sub
-
Jun 9th, 2004, 12:40 PM
#5
If your query joins more than two tables and you have referrential integrity enforced on your relationships, access will not let you modify the recordset returned.
-
Jun 9th, 2004, 01:26 PM
#6
Thread Starter
New Member
Thanks.
Is there no way round this
-
Jun 9th, 2004, 01:56 PM
#7
The reason your recordset is readonly is becuase it is made from data from lots of different tables.
If you change a row in your recordset then the table that the data comes from needs to be updated.
Take for example a students table, a courses table and an enrolments table.
Code:
+----------------+ +------------------+ +---------------+
| Students | | Enrolments | | Courses |
+----------------+ +------------------+ +---------------+
| StudentId (PK) |--|-----------<| StudentId | | CourseName |
| StudentName | | CourseId |>-------------|--| CourseId (PK) |
+----------------+ | EnrolmentId (PK) | +---------------+
| EnrolmentDate |
+------------------+
You use a query to give the following recordset:
Code:
| StudentName | CourseName | EnrolmentDate |
| | | |
If you attempt to change the student name or course name which reside in the student and courses table. How will access know whether the change you are making is to add a new student (i.e. a student that does not exist) or changing it to the name of a student who already exists. Unless the StudentName is the primary key in the students table (not advisable), Access has no way of knowing.
The best way of doing this is to open up the actual table you want to modify as a recordset. Don't use a query - you can then add records. You may need to open up several recordsets if you want to modify several tables.
For example - adding a student and enroling on a course would require:
- Open the students table recordset
- Insert a new student record
- Store the new students StudentId
- Close the student recordset.
- Open the courses recordset
- Search for the course you want (i.e. using the CourseName)
- Store the CourseID
- Close the courses recordset.
- Open the enrolemtns recordset.
- Insert the new enrolment using the CourseId and the StudentID remembered earlier.
As a rule of thumb. Select queries are for pulling data previously stored, not inserting - they should always be treated as read-only.
-
Jun 9th, 2004, 02:51 PM
#8
Thread Starter
New Member
Thanks I understand now, I appreciate you're explanation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|