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

Posted on 2003-11-04
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
  • 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 500 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.


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;en-us;103257

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

810 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