Store .wav file in Access table and later "save" the .wav file to disk

I'd like to deploy a database with some custom sounds.  Sounds are .wav files that the user is unlikely to have on their machine.

What I'd like to do is store the .wav file in a table and when the user opens the database, save the .wav file to a temp folder where it can be "played" by the application.

Same goes for .exe files that I'd like to distribute in the database.
Who is Participating?
Oh and I should have posted some code to play the sound (sorry not enough cafeine in the system yet).


'Create a module (I like to name them mdlGlobal usually)

'you'll have to call an API

'this API is a Windows API and will make playing
'the sound possible
Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
  (ByVal lpszName As String, ByVal hModule As Long, _
   ByVal dwFlags As Long) As Long

'Next, jst below it declare the following function

Public Function PlayWave(ByVal fName As String, ByVal iMode As _
                   Integer) As Integer
    PlayWave = PlaySound(fName, 0, iMode)
End Function

'Just to test it put this for now on a Button_Click event on your form

Private Sub Commandx_Click()
     Dim pSound As Integer
     pSound = PlayWave("c:\frog.wav", 1)
End Sub
Your could create a table with Fieldtype object where you put all your sound files.

Do you need code to loop through the records to place the object in your desired folder?

MS Access supports OLE objects. So what you can do is:

1) Create a new field and make it an OLE field
2) Open up the table and right click on the OLE field and select 'Insert Object'
3) Choose your .wav file

But that would not be my recommended solution (it is the easy one though), as OLE fields take up a lot of space. What you'd want to do is store the Path of the .wav file on the table in the database, then put all those .wav files on a separate folder(you can call it Sounds for example) and store the path on the table (C:\Sounds\hello.wav) and use that path to play the proper sound when the app opens or when the form opens (or whatever user action you want to trigger the sound)
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

One more thing...

If you store the path of the file in the database then you can replace the hardcoded path with the path stored in the database

for example if you had a table then create a recordset and assign the path to a local variable and  use it as in:

Dim pSound as Integer
Dim pPath as String

Dim rs as DAO.Recordset 'you can use an ADO recordset as well if you prefer

'enter code here to open table and fill the recordset

then you'd do something like this

pPath = rs("SoundPath")'where SoundPath could be your field with the sound path store in it

'then you'd say

pSound = PlayWave(pPath,1)

...this should work fine

As for the .exe's part, you can execute them using the Shell function

here's the syntax..


pathname: path to your exe (same as the .wav here)

windowstyle: 'taken from Access help

vbHide 0 Window is hidden and focus is passed to the hidden window. The vbHide constant is not applicable on Macintosh platforms.

vbNormalFocus 1 Window has focus and is restored to its original size and position.

vbMinimizedFocus 2 Window is displayed as an icon with focus.

vbMaximizedFocus 3 Window is maximized with focus.

vbNormalNoFocus 4 Window is restored to its most recent size and position. The currently active window remains active.

vbMinimizedNoFocus 6

here's an example

' Specifying 1 as the second argument opens the application in
' normal size and gives it the focus.
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)    ' Run Calculator. 1 means Normal Focus


jbpowellAuthor Commented:
OK this is great, so I can store the .wav file in an OLE type field.

Since I'm distributing the db to users, what kind of code is necessary to save the contents of the field (the .wav file) to the users hard drive?
I gave you the full solution. Did you even try it?

Why don't you distribute the DB to the users with the extra folder with the .wav files in it?

if you want to store them into the database then then you do not NEED to store them into the users hard drive, they will be store in the database (when you use a OLE type field)

jbpowellAuthor Commented:
I'm still looking for a way to save the contents of an ole field (be it a .wav file or an exe) to a user's hard drive.

Here's where I am so far:

1. I can play a wav file on my hard drive using the code L30 provided...L30 scores points for that!

2. I'm able to get a file into the database in an OLE field.

3. ??? How can I save the contents of an OLE field to a user's hard drive (I would probably check to see if the file exists, if not create a temp folder, then save the file to the temp folder)
May I ask you something? Why do you need to store the contents of the file on the users hard drive? Is there any specific reason for it? Will those files be used for anything else or only for that particular database?
jbpowellAuthor Commented:
The files will only be used for the database.  The database checks California energy prices on the web.  The website publishes information in .zip format.  In order to unzip files (using a shell command) I need to either know where the user installed winzip or I can put a copy of the wzzip.exe and wzunzip.exe files in the users path environment folder (specified in autoexec.bat).  It's much easier to execute a command line if you know where the .exe files are.

So my plan is to store the .exe files in the database itself (along with some cool sound files).  And copy them to a known location so the app can use them.
What file formats does the Web site zip? are those the files that you want to insert into the users database? Is this something that will happen repeatedly or is it a one time thing?

In order to unzip files (using a shell command) I need to either know where the user installed winzip or I can put a copy of the wzzip.exe and wzunzip.exe files in the users path environment folder (specified in autoexec.bat).  
--So the files that you want unzipped are located on a different place(shared drive), and you just want to use the users WinZip to unzip them? If that is the case can you unzip the files yourself and point the user's app to that location, or am I not understanding what exatcly you want to do? All programs in Windows are installed under C:\Program Files\XX

So if they have WinZip installed for example you can use shell to access it that way. Are these computers on a network?

So let me recap:

You want to store an .exe zip program on a user's database to unzip files. I still need to know where these zipped files are located?

You can always use Access to create a folder and store everything there, then you can *pre hard code* the path and make all the work happen the first time the users opens up the database. They can click a button that will create the folders and copy the files and sound files to that folder and point tha ms access application there every time it opens (run time using a .ini file), or easier to hardcode all the paths etc.

jbpowellAuthor Commented:
Does anyone know how to write a binary file stored in an Access table to disk?
here's a link.This will solve your problem;en-us;103257
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.