Results 1 to 8 of 8

Thread: read only problem RESOLVED

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    4

    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.

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    Sometimes I have inadvertantly opened my recordsets as Read-Only. You might check that sort of theing.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Post the code you're using to open the DB and save to it.

    What is datJobs?

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    4
    datJobs is the name of the data object
    the code used is

    Private Sub cmdNew_Click()
    datJobs.Recordset.AddNew
    End Sub

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    4
    Thanks.
    Is there no way round this

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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:
    1. Open the students table recordset
    2. Insert a new student record
    3. Store the new students StudentId
    4. Close the student recordset.
    5. Open the courses recordset
    6. Search for the course you want (i.e. using the CourseName)
    7. Store the CourseID
    8. Close the courses recordset.
    9. Open the enrolemtns recordset.
    10. 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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    4
    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
  •  



Click Here to Expand Forum to Full Width