Link to home
Start Free TrialLog in
Avatar of jbpowell
jbpowell

asked on

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.
Avatar of CSLARSEN
CSLARSEN

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?

Rgds
CS
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)
ASKER CERTIFIED SOLUTION
Avatar of L30
L30

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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..

Shell(pathname[,windowstyle])

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

cheers





Avatar of jbpowell

ASKER

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)

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?
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.


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

http://support.microsoft.com/default.aspx?scid=kb;en-us;103257