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