Hi
I wonder if any of you guys can help. I have been given the task at
work which Im struggling with...
We have a database which is getting large due to records with a field
of audio files (held as an ole object). I have been asked to extract
all the audio files from the database and store them on a seperate
place on the server.
I was wondering is there was a quick and easy method of extracting the
audio files from the table. There are about 80,000 records.
Can anyone help??
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Probably just run a query that gets the ole object, probably a BLOB, and
writes it to a file using VBA's WRITE # command. A problem is you have
to know the file's audio type: mp3, aud, ogg, etc. Also, media files
usually have header bytes that identify things about the file that are
required for the file to run. Do you know if your OLE objects have
those bytes? Probably the only way to find out is save one & try to
play it.
You'll need a query to get the OLE object (let's name it GetAudio):
SELECT file_name, ole_object
FROM table_name
WHERE file_name IS NOT NULL
Be sure to change the table & column names to match your table's &
columns' names.
Then some VBA routines to iterate through the query's recordset and
write the data to the files (that's why I included the file_name in the
query).
NOTE: These routines are untested!
Sub SaveAudioFiles()
' The PATH is the path to the folder where the files will
' be saved. Change to suit your needs.
Const PATH = "C:\myAudioFiles\"
' This is the query we created & saved, above
Const QRY = "GetAudio"
' This is the file extension - change to whatever file type
' you're saving the file.
Const EXT = ".mp3"
On Error GoTo err_
Dim db As DAO.Database, qd As DAO.QueryDef, rs As DAO.Recordset
' Get the recordset
Set db = CurrentDb
Set qd = db.QueryDefs(QRY)
Set rs = qd.OpenRecordset()
Do While NOT rs.EOF
SaveAudio PATH & rs!file_name & EXT, rs!ole_object
' For debug purposes uncomment the following line
' Just one file will be saved.
' Exit Do
rs.MoveNext
Loop
' If got here, then no errors
MsgBox "Completed", vbInformation, "Save Audio Files"
exit_:
' clean up & exit
On Error Resume Next
Set rs = Nothing
Set qd = Nothing
Set db = Nothing
Exit Sub
err_:
' You'll probably want a better Error Handler than this....
MsgBox "An Error Occurred While Saving Audio Files" & vbCrLf & _
"Error: " & Err.Description, vbExclamation
Resume exit_
End Sub
Sub SaveAudio(ByVal strFileName As String, obj As Object)
' Save one audio file
' If error, it is returned to the calling routine
Dim fd As Integer
' Get the next available file buffer
fd = FreeFile
' Open a new file & save the data
Open strFileName For Binary Access Write As fd
Write #fd, obj
Close fd
End Sub
HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBSd4sZIechKqOuFEgEQKm9wCdEArXBKwpbw+xYpY0nC6hQraSbAoAoJoF
YQzyezm8ZW4F02NoFwBk9ZvM
=fzQk
-----END PGP SIGNATURE-----