Results 1 to 5 of 5
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    Recordset 3201 Error

    I have a Form with a button: that when clicked will do the following
    Add the Now() date to a table, a sub table and two sub sub tables (I want to add more data but started small)

    Parent table tblDirectorsDD
    PK: DirDDKey
    FK: DDKey

    Child table: tblDirectorsIdentity
    PK: DirKey
    FK: CiKey

    Child Child table1: tblDirectorsGoogle
    PK: DDKey
    FK: DirKey

    Child Child table2: tblDirectorsInsolvency
    PK: DDKey
    FK: DirKey

    Private Sub BtnStartDirectors_Click() (From a from at the tblDirectorsDD level)
    Me.DirectorsDDDateStarted = Now()


    If Me.Dirty Then
    Me.Dirty = False
    End If


    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("tblDirectorsIdentity")
    rs.AddNew
    rs!CIKey = Me.DirDDKey
    rs!DirectorDateStarted = Now()
    rs.Update


    Set rs = CurrentDb.OpenRecordset("tblDirectorsGoogle")
    rs.AddNew
    rs!DirKey = Me.DirDDKey
    rs!GoogleDateStarted = Now()
    rs.Update


    Set rs = CurrentDb.OpenRecordset("tblDirectorsInsolvency")
    rs.AddNew
    rs!DirKey = Me.DirDDKey
    rs!InsolvencyDateStarted = Now()
    rs.Update
    End Sub

    My error comes in the form of a 3021 Error at the second rs.Update saying I can not add or change a record because a related record is required in tbldirectoorsidentity.

    I have used this code elsewhere in the database and it works fine to update multiple tables with data, but this is the first time I'm hitting this error. When I open table tbldirectorsidentit, the PK is complete, the FK is populated and the date is showing. So its clearly updating the first table, why wot it do the same to the child tables.

    Mousing over the vba shows that the correct data is ready to be saved, but what is missing to complete the save?



    Regards

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    So is tbldirectoorsidentity a parent table?

    A parent table is one where a record must exist before you can add a record in a child table?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I would think your DirDDKey should be the FK in the child tables. Without that field you have no relationship between the main and child tables. Or did you define a relationship but you've just named the FK fields something that's not obvious?
    Please use code tags (# on toolbar) to encapsulate code with indentation, and always state which code line causes an error.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    tblDirectorsDD is the parent table:


    Parent table tblDirectorsDD
    PK: DirDDKey linked to FK: CiKey
    FK: DDKey

    Child table: tblDirectorsIdentity
    PK: DirKey linked to FK: DirKey for both the below tables
    FK: CiKey

    Child Child table1: tblDirectorsGoogle
    PK: DDKey
    FK: DirKey

    Child Child table2: tblDirectorsInsolvency
    PK: DDKey
    FK: DirKey


  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    OK. If troubleshooting 6 months from now, you might think that this would be easier to follow
    Parent table tblDirectorsDD
    PK: DirDDKey

    Child table: tblDirectorsIdentity
    PK: DirKey
    FK: DirDDKeyFk

    At this point all I can suggest is to step through your code and ensure conditions/variables are what you expect. Perhaps the form is not dirty for some reason, thus the parent record is not saved. The message seems pretty clear - a parent record is not there for at least one child. Which is still a mystery but stepping through out to tell you which one it is.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Run time error help 3201
    By Steven19 in forum Forms
    Replies: 2
    Last Post: 03-31-2021, 01:28 AM
  2. RunTime error 3201
    By a14guguliye in forum Programming
    Replies: 2
    Last Post: 02-07-2020, 09:58 AM
  3. Recordset not found Error 3201
    By Thompyt in forum Programming
    Replies: 5
    Last Post: 01-15-2019, 03:23 PM
  4. Error 3201
    By JennyL in forum Access
    Replies: 11
    Last Post: 06-15-2018, 11:14 AM
  5. Error Handeling for a 3201 and 3022 Error
    By starlancer805 in forum Access
    Replies: 3
    Last Post: 03-11-2015, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums