I hadn't noticed before (how could I have missed it?), but the code from the tutorial does not actually extract the file from the database - instead it binds the picture to an Image control.
This wont work for other file types (and is a 'bad' method anyway), so you need some extra code. What you need to do is save the data to a file, and then use the file in whatever way is appropriate (possibly followed by deleting the file you saved).
Here is a sub I have written which saves the data to a file:
..and to use it, put the following code (or similar) in FillFields, replacing both lines that use "Image1":VB Code:
Sub SaveFileFromDB(strFileName As String, fldPictureField As ADODB.Field) 'Save data from a OLE/BLOB field to a file Dim intFileNum As Integer Dim bytChunk() As Byte 'open file for writing intFileNum = FreeFile Open strFileName For Binary As #intFileNum 'get data from database bytChunk() = fldPictureField.GetChunk(fldPictureField.ActualSize) 'write data to file Put #intFileNum, , bytChunk() 'close the file Close #intFileNum End Sub
VB Code:
Call SaveFileFromDB(App.Path & "\temp.tmp", rs.Fields("Picture"))
One thing to note is that in this example I have used a file name that may not work for you (temp.tmp).. for example, the way you play the audio files may need the file to have the correct extension (eg: .wav , or .mp3).
What I would recommend is adding an extra field to the database table, called FileName (with a data type of: Text). When you save data in cmdAdd_Click, set the value of this field to the name of the file (with the extension, but not the path), using code like this:
..you can then re-save the file using the original name, eg:VB Code:
.Fields("FileName") = MyFileName 'where MyFileName is a variable containing the file name
VB Code:
Call SaveFileFromDB(App.Path & "\" & rs.Fields("FileName").Value, rs.Fields("Picture"))




), but the code from the tutorial does not actually extract the file from the database - instead it binds the picture to an Image control. 
Reply With Quote