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

Posted on 2003-11-04
Medium Priority
Last Modified: 2013-01-28
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.
Question by:jbpowell
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
LVL 15

Expert Comment

ID: 9679335
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?


Expert Comment

ID: 9679413
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)

Accepted Solution

L30 earned 1500 total points
ID: 9679508
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 9679553
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


Expert Comment

ID: 9679595
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



Author Comment

ID: 9680021
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?

Expert Comment

ID: 9680083
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)


Author Comment

ID: 9680192
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)

Expert Comment

ID: 9680967
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?

Author Comment

ID: 9681090
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.

Expert Comment

ID: 9681870
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.


Author Comment

ID: 9682079
Does anyone know how to write a binary file stored in an Access table to disk?

Expert Comment

ID: 9686830
here's a link.This will solve your problem


Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question