Wayne, I really appreciate the well expalined post but I understand how to
make a module and where to put the code and how to find the path. My problem
is that I move that database around and the sound file wont be in the same
place as my home PC and work PC's. I wanted to do something as to where it
finds the path for example im using this in a report to bring up pictures
from a folder named RejectSteelBarCodes and this forlder always stays with my
DB. How would I incorporate something like this but use a folder named Sounds
to find the .wav file I am wanting? Oh and how about a delicious cookie baked
fresh from the oven instead of the cake....Thanks!
strPath = CurrentProject.Path & "\RejectSteelBarCodes\"
strDir = Dir(strPath)
--
Newbies need extra loven.........
:
Hi Chad
Playing a sound on various events in/on a form is quite simple (IF you know
how).
So 1st can we agree on my price.
I never charge less than one absolutely huge cream cake. You can send this
to me at Wayne-i-m c/o the British Post Office, England. I am sure it
will arrive sooner or later. Oh if a cream cake is too much I will let you
negotiate me down but no lower than a jam donut.
You say you have looked around for some help and can’t understand it – me
too, some of it, so don’t worry nothing is clear “until you get it, only then
is it simple.
If you have a look a the module on Allan Browns site
http://allenbrowne.com
You will it looks like this
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
(ByVal filename As String, ByVal snd_async As Long) As Long
Function PlaySound(sWavFile As String)
' Purpose: Plays a sound.
' Argument: the full path and file name.
If apisndPlaySound(sWavFile, 1) = 0 Then
MsgBox "The Sound Did Not Play!"
End If
End Function
So – to use this - do this
In your access database you will have (on the left of the screen) choices of
Tables
Queries
Forms
Reports
Pages
Macros
Modules
Select Modules
Select New
You will arrive at a screen with
Option Compare Database
Cut and paste Allan’s code (paste just below Option Compare Database) it
will now look like this
Option Compare Database
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
(ByVal filename As String, ByVal snd_async As Long) As Long
___________________________________________
Function PlaySound(sWavFile As String)
' Purpose: Plays a sound.
' Argument: the full path and file name.
If apisndPlaySound(sWavFile, 1) = 0 Then
MsgBox "The Sound Did Not Play!"
End If
End Function
I drew the line in the code above as that is what you will see . Save this
as whatever you want (but something that makes sense to you AND more
importantly anyone else who may, in the future, work on the programming)
Next
Open your form in design view
Right click the form area outside the detail section (the grey area)
Select properties
Select the Event Column
Right click the OnLoad row
Select Build (…)
Select Code
You will see this
Private Sub Form_Load()
End Sub
You need to write only one line of code (like this)
PlaySound (Path to WAV file)
It will look something like (but not exactly like) this
Private Sub Form_Load()
PlaySound ("C:\WINDOWS\Media\chord.wav")
End Sub
OK up to now I hope. You MUST know the full path of the WAV.
You can get it by clicking
Start
Run
Browse
(Select all files in the file type box)
Navigate to your WAV file and select it.
Click run
Cut the path out of the run box and paste it into the code between the ( )
Hey-presto
Hope this helps
--
Wayne
Manchester, England.
:
PACALA, The discussion Group isn’t a place to do business it’s a place to
help people! I think this is very unprofessional....
Newbies need extra loven.........
:
NO PROBLEMS, CONTACT ME...
--
PACALA JAN [ACCESS DEVELOPER]
SEND 10$ TO...
ACCOUNT:
SK31 1100 0000 0026 1674 0428
SwiftCode: TATRSKBX
Tatra banka as,Hodzovo nam.3, 811 06 Bratislava
(e-mail address removed)
SKYPE: PACALA.BA1
:
Hello, I have a file named song1.wav and its in a folder named Songs. How do
I have my database play this song at startup. I move my database to and from
work so the file path wont be the same but the folder "Songs" is always with
the database. I have found the code below and it works but its pointing to
windows media folder ect. Here is the code:
Module:
Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal
lpszSoundName As String, ByVal uFlags As Long) As Long
Public Sub PlaySound(strSound)
Call sndPlaySound32(strSound, 0)
End Sub
On load event of my opening form:
Call PlaySound("C:\Windows\Media\Whoosh.wav")
Thanks!!!