2011/05/18

access2010 access2007 添付フィールド/複数値フィールド付レコードコピー


Sub CopyRecord_Attachment_MultiValues()
    Dim rs1 As DAO.Recordset, rs1a As DAO.Recordset, rs1m As DAO.Recordset
    Dim rs2 As DAO.Recordset, rs2a As DAO.Recordset, rs2m As DAO.Recordset
    Dim dbs As DAO.Database
    
    Set dbs = CurrentDb
    
    Set rs1 = dbs.OpenRecordset( _
        "SELECT F01, F_attachment, F_multivalue FROM table01 WHERE ID = 1;")
    Set rs1a = rs1("F_attachment").Value
    Set rs1m = rs1("F_multivalue").Value
    
    Set rs2 = dbs.OpenRecordset( _
        "SELECT F01, F_attachment, F_multivalue FROM table02;")

    rs2.AddNew
        rs2.Fields("F01") = rs1.Fields("F01")
        
        Set rs2a = rs2("F_attachment").Value
        
        Do Until rs1a.EOF
            rs2a.AddNew
                rs2a.Fields("FileData") = rs1a.Fields("FileData")
                rs2a.Fields("FileName") = rs1a.Fields("FileName")
            rs2a.Update
            rs1a.MoveNext
        Loop
        
        Set rs2m = rs2("F_multivalue").Value
        
        Do Until rs1m.EOF
            rs2m.AddNew
                rs2m.Fields("Value") = rs1m.Fields("Value")
            rs2m.Update
            rs1m.MoveNext
        Loop
    rs2.Update

End Sub

0 件のコメント: