CopyRecord, CopyTo, and SaveToFile Methods Example (VB)

Microsoft ActiveX Data Objects (ADO)

CopyRecord, CopyTo, and SaveToFile Methods Example (VB)

This example demonstrates how to create copies of a file using Stream or Record objects. One copy is made to a Web folder for Internet publishing. Other properties and methods shown include Stream Type, Open, LoadFromFile, and Record Open.

Public Sub CopyRecordX()
    ' Declare variables
    Dim strPicturePath, strStreamPath, strStream2Path, _
        strRecordPath, strStreamURL, strRecordURL As String
    Dim objStream, objStream2 As Stream
    Dim objRecord As Record
    Dim objField As Field
    
    ' Instantiate objects
    Set objStream = New Stream
    Set objStream2 = New Stream
    Set objRecord = New Record
    
    ' Initialize path and URL strings
    strPicturePath = _
    "C:\Program Files\Microsoft Office\Clipart\Popular\Checkmrk.wmf"
    strStreamPath = "\\websrv\folder\mywmf.wmf"
    strStreamURL = "URL=http://websrv/folder/mywmf.wmf"
    strStream2Path = "D:\samples\check2.wmf"
    strRecordPath = "\\websrv\folder\mywmf.wmf"
    strRecordURL = "http://websrv/folder/mywmf.wmf"
    
    ' Load the file into the stream
    objStream.Open
    objStream.Type = adTypeBinary
    objStream.LoadFromFile (strPicturePath)
    
    ' Save the stream to a new path and filename
    objStream.SaveToFile strStreamPath, adSaveCreateOverWrite
       
    ' Copy the contents of the first stream to a second stream
    objStream2.Open
    objStream2.Type = adTypeBinary
    objStream.CopyTo objStream2
    
    ' Save the second stream to a different path
    objStream2.SaveToFile strStream2Path, adSaveCreateOverWrite
    
    ' Because strStreamPath is a Web Folder, open a Record on the URL
    objRecord.Open "", strStreamURL
    
    ' Display the Fields of the record
    For Each objField In objRecord.Fields
        Debug.Print objField.Name & ": " & objField.Value
    Next
    
    ' Copy the record to a new URL
    objRecord.CopyRecord "", strRecordURL, , , adCopyOverWrite
    
    ' Load each copy of the graphic into Image controls for viewing
    Image1.Picture = LoadPicture(strPicturePath)
    Image2.Picture = LoadPicture(strStreamPath)
    Image3.Picture = LoadPicture(strStream2Path)
    Image4.Picture = LoadPicture(strRecordPath)
    
    ' Clean up
    objStream.Close
    objStream2.Close
    objRecord.Close
End Sub