Solved

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

Posted on 2003-11-04
13
600 Views
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.
0
Comment
Question by:jbpowell
  • 8
  • 4
13 Comments
 
LVL 15

Expert Comment

by:CSLARSEN
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?

Rgds
CS
0
 
LVL 1

Expert Comment

by:L30
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)
0
 
LVL 1

Accepted Solution

by:
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).

Here:

'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
0
 
LVL 1

Expert Comment

by:L30
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


0
 
LVL 1

Expert Comment

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





0
 

Author Comment

by:jbpowell
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?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Expert Comment

by:L30
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)

0
 

Author Comment

by:jbpowell
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)
0
 
LVL 1

Expert Comment

by:L30
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?
0
 

Author Comment

by:jbpowell
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.
0
 
LVL 1

Expert Comment

by:L30
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.


0
 

Author Comment

by:jbpowell
ID: 9682079
Does anyone know how to write a binary file stored in an Access table to disk?
0
 
LVL 1

Expert Comment

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

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now