Results 1 to 3 of 3
  1. #1
    mixedup is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Dec 2014
    Posts
    10

    Question programmatically create a relationship table row in VBA ADO? (getting "Compile error: qualifie...

    How do I programmatically create a relationship table row in VBA ADO? I'm getting an error here when trying? i.e. "Compile error: qualifier must be a collection" (at the point indicated in the code)



    I basically have two tables: items (ID, title, amount) and relationships(parentId, clientId). I'm basically just trying here to create a New Record in items, and then creating a new relationship table record as well. I'm not sure how to allocate the the new Item record (just created) to the new Relationship record's "childId" field?

    Code:
    Private Sub Command18_Click()
        Debug.Print ("*** Starting ***")
    
        ' New Record
        Dim rsItems As Recordset
        Set rsItems = CurrentDb.OpenRecordset("items")
        rsItems.AddNew
        rsItems![title] = "title"
        rsItems![amount] = 123
        rsItems.Update
    
        ' Get new ID
        rsItems.Bookmark = rsItems.LastModified
        newId = rsItems.Bookmark
        Debug.Print ("New ITEM record with ID " & newId)
    
        ' Relationships
        Dim rsRelationship As Recordset
        Set rsRelationship = CurrentDb.OpenRecordset("relationships")
        rsRelationship.AddNew
        'Debug.Print ("Relationships Field Types: " & TypeName(gcItemParentId) & ", " & TypeName(rsItems.LastModified!ID))
        rsRelationship![parentId] = gcItemParentId  'taken from text box on main form that holds current parent ID
        rsRelationship![clientId] = rsItems.LastModified!["ID"] ' *** ERROR HERE *** 
        rsRelationship.Update
    
        ' Get new ID
        rsRelationship.Bookmark = rsRelationship.LastModified
        newId = rsItems.Bookmark
        Debug.Print ("New RELATIONSHIP record with ID " & newId)
    
        ' Refresh Form
        Me.Refresh
    
        ' Cleanup
        rsItems.Close
        rsRelationship.Close
        Set rsItems = Nothing
        Set rsRelationship = Nothing
    
    End Sub

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Take the quotes out of ["ID"] - they are not required in that context.

  3. #3
    mixedup is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Dec 2014
    Posts
    10
    thanks..............

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

Similar Threads

  1. Replies: 2
    Last Post: 12-09-2014, 09:24 AM
  2. Replies: 10
    Last Post: 09-08-2014, 06:07 PM
  3. Replies: 5
    Last Post: 06-19-2013, 10:24 AM
  4. Programmatically create a ACCDE
    By srbond@hotmail.com in forum Programming
    Replies: 2
    Last Post: 11-18-2010, 08:00 AM
  5. Replies: 1
    Last Post: 05-13-2010, 10:50 AM

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