Results 1 to 4 of 4

Thread: How to save/Retrieve WAVE files from/to an Access DB

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    5

    Talking

    How can I save and retrieve WAVE files from/to an Access database using only VB Code?

    I can do it with the OLE container and ADO/DAO controls but how about without using any OLE container?


    Your help is really appreciated!
    [email protected] (Jelatinas)

  2. #2
    Zaei
    Guest
    You probably can't unless you wanted to save the ENTIRE wave file as a string. If you want to know how to do that, look around the forums, because I'm not sure how.

    Z.

  3. #3
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    I know how to do it using DAO, but it should be similar using ADO. In your database, create a field called something like WaveData, with the dbLongBinary type (or OLE_OBJECT as it's called in Access I think). Then you can just read and write the WAV file like this: (DAO sample)

    Code:
    Dim WS As DAO.Workspace
    Dim DB As DAO.Database
    Dim RS As DAO.Recordset
    Dim bData() As Byte
    Dim iFree As Integer
    
    ' Open the database, And the 'Waves' table...
    Set WS = DBEngine.Workspaces(0)
    Set DB = WS.OpenDatabase("c:\wav.mdb")
    Set RS = DB.OpenRecordset("Waves")
    
    ' Read the WAV file
    iFree = FreeFile()
    Open "c:\sample.wav" For Binary Access Read As #iFree
    ReDim bData(LOF(iFree))
    Get #iFree, , bData()
    Close #iFree
    
    ' Add it To the database
    RS.AddNew
    RS("WaveData") = bData()
    RS.Update
    
    ' Now To read it again, move To the first item (To keep it simple)
    RS.MoveFirst
    
    ' Size the Byte array And read it from the DB
    ReDim bData(RS("WaveData").FieldSize)
    bData() = RS("WaveData")
    
    ' Now you can Write it To a file again, like this:
    iFree = FreeFile()
    Open "c:\fromdb.wav" For Binary Access Write Lock Read Write As #iFree
    Put #iFree, , bData()
    Close #iFree
    
    ' Close the DB
    Set RS = Nothing
    Set DB = Nothing
    Set WS = Nothing
    Hope this helps...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    5
    It works!!!!!!

    Thank you very much PsychoMark!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width