Solved Sound in Access (1 Viewer)

murray83

Games Collector
Local time
Today, 11:57
Joined
Mar 31, 2017
Messages
736
I would like to put some sounds in access nd found this


but not sure if thats the best way could some one look and maybe point in another direction

cheers all
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:57
Joined
Sep 21, 2011
Messages
14,362
Seems simple enough?
What are your concerns?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:57
Joined
Feb 28, 2001
Messages
27,229
If you want specific sounds other than the result of the VBA BEEP verb, you have to call an API function to play a .WAV or other type of sound file, which is what you got in that link. But heck, you can go completely crazy if you wish - because Excel has a Text To Speech feature that you could call through VBA and have your DB talk to you.

HINT: Take a VERY conservative approach when playing with sounds. Users will think they are either a great toy or a total annoyance. The folks who treat it as a toy usually have neighbors who will hate YOU for giving them the toy. I say this from an unfortunate experience I had where I enabled Text To Speech abilities.

 

murray83

Games Collector
Local time
Today, 11:57
Joined
Mar 31, 2017
Messages
736
Seems simple enough?
What are your concerns?

well first concern was when i pasted it in the declarations went all ride line on me, as shown
 

Attachments

  • red lines of death.JPG
    red lines of death.JPG
    81.6 KB · Views: 83

murray83

Games Collector
Local time
Today, 11:57
Joined
Mar 31, 2017
Messages
736
sorry for the DP but this is the example i have done as when they press use potion i would like it to make a sound rather then normal access boings and bleeps
 

Attachments

  • BattleDemo2.2.accdb
    1 MB · Views: 79

Gasman

Enthusiastic Amateur
Local time
Today, 11:57
Joined
Sep 21, 2011
Messages
14,362
well first concern was when i pasted it in the declarations went all ride line on me, as shown
Are you using 64 bit Access, as that works fine for my 32bit 2007 Access?
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:57
Joined
Sep 21, 2011
Messages
14,362
No, you just need to adjust it for 64 bit, or test for it and use the correct syntax.
Asked plenty of times on here, so search the site, or google for syntax.
It has never interested me, as I only have 32bit, and everyone used the same.
 

isladogs

MVP / VIP
Local time
Today, 11:57
Joined
Jan 14, 2017
Messages
18,247
I agree completely about using sound sparingly otherwise you will annoy your users.
Having said that it does have its uses.
Two examples of apps using sound

Text to speech is also available in Access and is used in the second app above
 

murray83

Games Collector
Local time
Today, 11:57
Joined
Mar 31, 2017
Messages
736
I agree completely about using sound sparingly otherwise you will annoy your users.
Having said that it does have its uses.
Two examples of apps using sound

Text to speech is also available in Access and is used in the second app above

thank you for the help, love your clock countdown, glad i had head phones when i put klaxon and ran it :)
 

isladogs

MVP / VIP
Local time
Today, 11:57
Joined
Jan 14, 2017
Messages
18,247
Yup. Meant to be annoying! Proves the point about using sound sparingly

The code in that app should be transferable for your purposes. Make sure the sound is run asynchronously so it can be stopped by the user

I know of an Access developer who uses text to speech in multiple places on every form. That would drive me demented!
 

murray83

Games Collector
Local time
Today, 11:57
Joined
Mar 31, 2017
Messages
736
@isladogs just got one question.

what have i done wrong, i belive i have the code right ( the code is in the form final battle on potion button ) but no sound but before when i have steped into it has played ( and played and played until i close access )

would you mind helping out if you can have a look :)
 

Attachments

  • BattleDemo2.2.zip
    376.5 KB · Views: 74

Eugene-LS

Registered User.
Local time
Today, 13:57
Joined
Dec 7, 2018
Messages
481
what have i done wrong, i belive i have the code right ( the code is in the form final battle on potion button ) but no sound but before when i have steped into it has played ( and played and played until i close access )
Try :
Code:
Private Sub TestPlayWaveFile()
'... \Sounds\potion_gulp.wav
    strSound = CurrentProject.Path & "\Sounds\potion_gulp.wav"
    PlayWaveFile
    StopWaveFile
End Sub
... Works!
 

murray83

Games Collector
Local time
Today, 11:57
Joined
Mar 31, 2017
Messages
736
Try :
Code:
Private Sub TestPlayWaveFile()
'... \Sounds\potion_gulp.wav
    strSound = CurrentProject.Path & "\Sounds\potion_gulp.wav"
    PlayWaveFile
    StopWaveFile
End Sub
... Works!
You say works but do you hear a sound then that plays just once as i did that and nothing so put a break in and steped into and played and played :( and played
 

isladogs

MVP / VIP
Local time
Today, 11:57
Joined
Jan 14, 2017
Messages
18,247
@murray83
You can't hear anything as you forgot to add the line PlayWaveFile after the strSound line

That very Irritating sound then plays four times but that only happens after the OK button is clicked on the message box
 

murray83

Games Collector
Local time
Today, 11:57
Joined
Mar 31, 2017
Messages
736
thanks for that but i think it is my laptop ( well work laptop ) as the sound doesn't play either time on but will play in the folder
 

murray83

Games Collector
Local time
Today, 11:57
Joined
Mar 31, 2017
Messages
736
@murray83
You can't hear anything as you forgot to add the line PlayWaveFile after the strSound line

That very Irritating sound then plays four times but that only happens after the OK button is clicked on the message box

But then how do i make it only play once, im guessing change the play code or the wait and also how do i make it play before the OK button in the message is pressed, is that based on where it comes in the code
 

isladogs

MVP / VIP
Local time
Today, 11:57
Joined
Jan 14, 2017
Messages
18,247
You need to move the message box line after the sound plays.
Message boxes are modal so other code cannot run until OK is pressed.

I'm on my phone so can't run code at the moment.
To prevent the sound playing repeatedly, try reducing the Wait or removing it completely.
If something is needed to pause the code, try using DoEvents instead
 

Users who are viewing this thread

Top Bottom