Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Item not found in collection (MSACCESS2003)

    I am trying to put a record in a parent table, and then add records to a child table. I am trying to get the value of the primary key in the first table to put in the foreign key of the child table, however it highlights on the DirID saying its not in the collection. I have tried putting the statement of PK before the Update command and after, but still reports it's not in the collection - but it is in the table - Primary key. Can someone tell me why, thanks

    rst.AddNew
    rst![MainDirName] = Me.Text57

    rst.Update
    rst.MoveLast
    PK = rst(DirID) ' Primary Key generated by added record

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Item not found in collection (MSACCESS2003)

    Assuming that DirID is the name of the field, you should use rst("DirID") i.e. quotes around the name. The way it is now, VBA assumes that DirID is the name of a variable.

    You should retrieve the value of DirID BEFORE rst.Update.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Item not found in collection (MSACCESS2003)

    Thankyou Hans, now it works. Best regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •