Play .wav file at DB start-up

C

Chad

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!!!
 
D

Douglas J. Steele

You'll need to determine the exact path to folder Songs, and then use

Call PlaySound(strFolder & "Whoosh.wav")

Note that there are problems using the sndPlaySound function with long file
names. If you need to, check http://www.mvps.org/access/api/api0020.htm at
"The Access Web" for code to convert from long file names to short file
names.
 
C

Chad

I found that prior and have no clue on what to place where so I didnt go any
further. Can you explain? Thanks!
 
T

Tony Toews [MVP]

Chad said:
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.

Not know what this song is I sure hope you have the ability to
1) turn it off when playing
2) tell the app to never play that song again in the future.
Otherwise your users could get very irritated at you.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
C

Chad

its only a two second start up song! and I need to add click.wav files for my
img buttons... I have been trying to figure this out for a few days now can
someone give me an example of what I need to do? Im getting pieces of
information and I reserch it just to find out I have no clue what they are
talking about. Im just starting out with access so please explain. Thanks!
 
P

PACALA

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
 
C

Chad

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


PACALA said:
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


Chad said:
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!!!
 
W

Wayne-I-M

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.



Chad said:
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.........


PACALA said:
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


Chad said:
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!!!
 
C

Chad

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


Wayne-I-M said:
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.



Chad said:
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.........


PACALA said:
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!!!
 
T

tina

these newsgroups are for the FREE exchange of ideas, information, and
assistance. this is absolutely NOT the place to troll for business, such
postings are not welcome, and they make such a bad impression that it can
only hurt your reputation in the Access community.

if you want to post actual advice and assistance here in the newsgroups for
all to benefit from, or post questions of your own, then your participation
will be welcomed.


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


Chad said:
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!!!
 
W

Wayne-I-M

Hi

The obvious answer is to copy the WAV file into a folder that also holds the
Database.

Would this be a problem.

--
Wayne
Manchester, England.



Chad said:
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.........


Wayne-I-M said:
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.



Chad said:
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!!!
 
T

Tony Toews [MVP]

Wayne-I-M said:
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.

Well said. I'll have to try that myself some day.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
C

Chad

Yes that is the obvious answer! But, What if I move my databse from point A
to point B all the time? Now im going to have to change the path on every
button in my datbase to wherever the sound file resides Right? Thanks!
--
Newbies need extra loven.........


Wayne-I-M said:
Hi

The obvious answer is to copy the WAV file into a folder that also holds the
Database.

Would this be a problem.

--
Wayne
Manchester, England.



Chad said:
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.........


Wayne-I-M said:
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!!!
 
C

Chad

Thank you tina!!!
--
Newbies need extra loven.........


tina said:
these newsgroups are for the FREE exchange of ideas, information, and
assistance. this is absolutely NOT the place to troll for business, such
postings are not welcome, and they make such a bad impression that it can
only hurt your reputation in the Access community.

if you want to post actual advice and assistance here in the newsgroups for
all to benefit from, or post questions of your own, then your participation
will be welcomed.


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


Chad said:
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!!!
 
C

Chad

Ok I figured it out! Here is what I did incase someone needs to do the same
thing.
First create a folder named "AccessSounds" and put your .wav files in it
that your going to use. Then create a module and name it ModPlaySound:

Option Compare Database
Option Explicit

Const SND_ASYNC = (1)
Const SND_NODEFAULT = (2)

Declare Function sndplaysound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal
lpszSoundName As String, ByVal uFlags As Long) As Long

' FROM: http://www.techonthenet.com/access/questions/play_wav.php
Public Sub API_PlaySound(pWavFile As String)
Dim LResult As Long

'Make a Windows API call to play a wav file
LResult = sndplaysound(pWavFile, SND_NODEFAULT + SND_ASYNC)

End Sub

Then in your on click event of a button or wherever you are going to have
the sound play use this line of code:

API_PlaySound CurrentProject.Path & "\AccessSounds\sm_click.wav"

It finds the curent project path and the folder "AccessSounds" and the .wav
file you want to use....
 
W

Wayne-I-M

I think you may be over complecating this whole thing. All you want to do is
play a quite tune - right. Why not just ensure that the wav file is on your c
drive in a folder containg the db and the wav. You say you have a folder -
RejectSteelBarCodes - just copy the wav file into this and it should work.
If this is not an option then just make sure that the wav file is on the c
drive of the front ends - where used.

It really isn't that complecated


--
Wayne
Manchester, England.



Chad said:
Yes that is the obvious answer! But, What if I move my databse from point A
to point B all the time? Now im going to have to change the path on every
button in my datbase to wherever the sound file resides Right? Thanks!
--
Newbies need extra loven.........


Wayne-I-M said:
Hi

The obvious answer is to copy the WAV file into a folder that also holds the
Database.

Would this be a problem.

--
Wayne
Manchester, England.



Chad said:
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!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top