Trying to copy a parent/child record combination and encountering code failure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HSXWillH
    New Member
    • Apr 2008
    • 57

    Trying to copy a parent/child record combination and encountering code failure

    Okay, I have records that some underlying data is the same, but in some subforms, you might have variable input that uniquely ID's each stock item.

    I've gotten the coding to copy both the parent and child records with no problems, but I'm running into continual issue with part of the parent recordset.

    My table is tblStockHeader --- relevent fields are Item_Type, UoM, Sport, Card_Year, Brand, Card_Number and Subset. All are text fields as Card_Year could be 99/00 and Card_Number often contain lettering. I get runtime 2465 Error when I click on my command Copy Button that says that Access can't find the 'Card_Number' referred to in the expression. I have verified multiple times the spelling is correct in both and since the other fields copy over properly, I don't believe it's the underlying tbl issue.

    DISREGARD: Turns out my form I was copying from was using a different query to pull together some different information. Once I verified that Card_Number was part of the rowsource for that, it resolved itself.


    Code:
    Dim db As Database
    Dim recBusiness As DAO.Recordset
    Dim recPlayerFrom As DAO.Recordset
    Dim recPlayerTo As DAO.Recordset
    Dim recStkAttrFrom As DAO.Recordset
    Dim recStkAttrTo As DAO.Recordset
    Dim lngBusinessKey As Long
    
    Set db = CurrentDb
    
    If Not IsNull(Me.Stock_ID) Then
    
        Set recBusiness = db.OpenRecordset("tblStockHeader", dbOpenDynaset)
    
        'copy the parent record and remember its key
        recBusiness.AddNew
        recBusiness!Item_Type = Me!Item_Type
        recBusiness!UoM = Me!UoM
        recBusiness!Sport = Me!Sport
        recBusiness!Card_Year = Me!Card_Year
        recBusiness!Brand = Me!Brand
        recBusiness!Card_Number = Me!Card_Number
        recBusiness!Subset = Me!Subset
        recBusiness.Update
        recBusiness.Bookmark = recBusiness.LastModified
        lngBusinessKey = recBusiness!Stock_ID
        
        recBusiness.Close
        Set recBusiness = Nothing
    Last edited by HSXWillH; Oct 13 '10, 10:10 PM. Reason: Problem solved.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Try a change in Syntax, specifically Line# 11:
    Code:
    If Not IsNull(Me.Stock_ID) Then
      Set recBusiness = db.OpenRecordset("tblStockHeader", dbOpenDynaset)
        With recBusiness
          'copy the parent record and remember its key
          .AddNew
             !Item_Type = Me!Item_Type
             !UoM = Me!UoM
             !Sport = Me!Sport
             !Card_Year = Me!Card_Year
             !Brand = Me!Brand
             !Card_Number = Me![Card_Number]
             !Subset = Me!Subset
          .Update
             .Bookmark = .LastModified
             lngBusinessKey = !Stock_ID
        End With
      
        recBusiness.Close
        Set recBusiness = Nothing
    End If

    Comment

    Working...