Calling A Module

  • Thread starter Thread starter Martin Tudge
  • Start date Start date
M

Martin Tudge

Hi All
I have created a module called 'Soundthings' to play a
sound within Access.
Beliow is the procedures I have put into the module.
The only issue now is how do i call up the procedure
below to play the sound.

Hope someone can help.
Regards
Martin
________________________________________________
Option Compare Database
Option Explicit

Declare Function sndPlaySound Lib "Winmm.dll"
Alias "sndPlaySoundA" (ByVal lpszSoundName As String,
ByVal uFlags As Long) As Long
Public Const KEY_RETURN = &HD
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_NODEFAULT = &H2
Public Const SND_LOOP = &H8
Public Const SND_NOSTOP = &H10

Public Sub PlaySound(pFile As String)

sndPlaySound pFile, SND_SYNC
End Sub

Public Sub PlayIntro()
Dim s As String
s = DBEngine(0)(0).Name
While Right$(s, 1) <> "\": s = Left$(s, Len(s) - 1): Wend
s = s & "SETUP0.WAV"

PlaySound s

End Sub
 
These are the 3 functions that I use to play wav files.
I CALL it in the form open event like this:

PlaySound ("The Microsoft Sound.wav")

Paste these 3 functions into a Module:
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal
filename As String, ByVal snd_async As Long) As Long
Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long


Public Function PlaySound(msound)
Dim XX%
Dim rtn As Integer
rtn = waveOutGetNumDevs() 'check for a sound card in the machine
If rtn = 1 Then 'a sound card exists
XX% = apisndPlaySound(msound, 1) 'play mmwave sound
Else ' no sound card was found
End If

'If XX% = 0 Then MsgBox ("The Sound Did Not Play! Because you don't have a
sound card.")
End Function
 
Thanks for that, but I am still having trouble.
The sound file I am trying to play is called SETUP0.WAV
and is in the same folder as the database.
Please break this down for me as it is really complicated.
Cheers.
 
Paste these 3 functions into a Module means you copy and paste the code into
a module and then save the module using a name like module1.

Then you go to a form and edit it.
In the form open event you write this code:

PlaySound ("SETUP0.WAV")

Then you run the form.
The sound plays when the form opens.
 
Hi Joe
Did what you said and got an error message saying 'The
macro(or its macro group) doesn't exist,'
Do you think its because I am using access 97 on a windows
xp pc?
Regards
Martin
 
No.
There is something else wrong.
Perhaps you are using an old form with macros attached to it?

Use a brand new form and only put this one line of code in the Form Open
event.
You have to use an Event procedure, not a macro.
 
Back
Top