How the Beep Action works using Macro or VBA? (1 Viewer)

silversun

Registered User.
Local time
Yesterday, 23:16
Joined
Dec 28, 2012
Messages
204
Hello,
I have a button to save my data. Before save procedure runs I have a Beep in my code as follows here but it doesn't create a Beep sound. Is there something that I've missed in my VBA code? I also tried to do the same with Macro Builder and got no beep sound.
Code:
Private Sub btn_save_Click()
Beep
answer = MsgBox("Your record is ready to be saved. Are you sure you want to save it?", vbYesNo)
If answer = vbNo Then
Me.btn_clear.SetFocus
Exit Sub
End If

Thank you for helps
 

isladogs

MVP / VIP
Local time
Today, 07:16
Joined
Jan 14, 2017
Messages
18,247
The obvious question is whether you have the sound volume muted?
 

silversun

Registered User.
Local time
Yesterday, 23:16
Joined
Dec 28, 2012
Messages
204
The obvious question is whether you have the sound volume muted?
No. I haven't.
I can watch YouTube videos from my computer with sound. Even other applications are sending me notifications with sound.
 

isladogs

MVP / VIP
Local time
Today, 07:16
Joined
Jan 14, 2017
Messages
18,247
OK so test the command on its own.
In the VBE Immediate window, type Beep and press return.
Does that work?

EDIT
It may be that the rest of the code is running before the beep occurs.
Try adding the line DoEvents immediately after the Beep line.
This will allow time for the processor to complete the previous task before continuing
 
Last edited:

silversun

Registered User.
Local time
Yesterday, 23:16
Joined
Dec 28, 2012
Messages
204
OK so test the command on its own.
In the VBE Immediate window, type Beep and press return.
Does that work?
No. It doesn't create any sound.
Here is my screenshot:
1588112489301.png
 

isladogs

MVP / VIP
Local time
Today, 07:16
Joined
Jan 14, 2017
Messages
18,247
I edited my post after you read it. May be worth trying what I added but I doubt it will help in your case.
Beep is a member of the standard VBA reference library which should be installed by default.

If that doesn't help, try creating a new database and again test in the immediate window
 

silversun

Registered User.
Local time
Yesterday, 23:16
Joined
Dec 28, 2012
Messages
204
Hi. Pardon me for jumping in... This probably won't make any difference, but could you also try this in the Immediate Window?

DoCmd.Beep

Either command works for me.
Nothing happens
:((
 

silversun

Registered User.
Local time
Yesterday, 23:16
Joined
Dec 28, 2012
Messages
204
I edited my post after you read it. May be worth trying what I added but I doubt it will help in your case.
Beep is a member of the standard VBA reference library which should be installed by default.

If that doesn't help, try creating a new database and again test in the immediate window
I created a new simple database and created a form. In the form I have a button and this following code behind it.
Both cases tested. It doesn't create a sound at all.
Code:
Private Sub Command1_Click()
'Beep
DoCmd.Beep
End Sub
 

Micron

AWF VIP
Local time
Today, 02:16
Joined
Oct 20, 2018
Messages
3,478
There is a setting in Options>Client Settings>Provide Feeback With Sound
I've always thought this was for Beep, but I just tried Beep in the immediate window of a db where the option was unchecked and it still worked. If it's not a Window level setting (some sounds options are for different things) then I don't know. You could try an API. I think if it works, it's an application level problem. If not, I'd be looking in System settings. The API would be like

Code:
Public Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Call it like
Beep 800, 100
That assumes you're not using 64 bit Office/Access.
 

silversun

Registered User.
Local time
Yesterday, 23:16
Joined
Dec 28, 2012
Messages
204
There is a setting in Options>Client Settings>Provide Feeback With Sound
I've always thought this was for Beep, but I just tried Beep in the immediate window of a db where the option was unchecked and it still worked. If it's not a Window level setting (some sounds options are for different things) then I don't know. You could try an API. I think if it works, it's an application level problem. If not, I'd be looking in System settings. The API would be like

Code:
Public Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Call it like
Beep 800, 100
That assumes you're not using 64 bit Office/Access.
I know my computer runs on a 64-bit Windows 7 Pro.
I am not sure how to use your code. I copied and paste it in my VBA module as it is but it gives me compile error.
Thanks for helping.
 

Micron

AWF VIP
Local time
Today, 02:16
Joined
Oct 20, 2018
Messages
3,478
I know my computer runs on a 64-bit Windows 7 Pro.
I am not sure how to use your code. I copied and paste it in my VBA module as it is but it gives me compile error.
Thanks for helping.
Hmm, that's what I expected because I assumed the Long needs to be declared PtrSafe. Too complicated to go there at this time I think. 2 things to try:
1) Check your sounds in control panel & see if there is no specified sound for the default sound.
2) See if your code is running too fast (that's what the DoEvents was about - you tried that?)
Code:
Public Function Beeper()
Dim i as Integer
For i=1 To 200
DoCmd.Beep
Next
End Function
You should be able to call it from the immediate window as
Beeper
If you don't hear anything, put a break on the start of the code and repeat the call to be sure that code runs.
EDIT - Never mind. I guess that code is too old for newer processors. I tried it with my pc and it didn't beep until the loop was finished.
 

silversun

Registered User.
Local time
Yesterday, 23:16
Joined
Dec 28, 2012
Messages
204
Hmm, that's what I expected because I assumed the Long needs to be declared PtrSafe. Too complicated to go there at this time I think. 2 things to try:
1) Check your sounds in control panel & see if there is no specified sound for the default sound.
2) See if your code is running too fast (that's what the DoEvents was about - you tried that?)
Code:
Public Function Beeper()
Dim i as Integer
For i=1 To 200
DoCmd.Beep
Next
End Function
You should be able to call it from the immediate window as
Beeper
If you don't hear anything, put a break on the start of the code and repeat the call to be sure that code runs.
EDIT - Never mind. I guess that code is too old for newer processors. I tried it with my pc and it didn't beep until the loop was finished.
I just realized my computer does not play any sound except for the videos and some other applications and I didn't even notice that until you told me to check the control panel.
Now I need to figure out how to fix that before I can solve this.
Thank you
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:16
Joined
Feb 28, 2001
Messages
27,236
If you can get to your Windows "Control Panel" there is a Sounds section. One of the options brings up the Sounds "control panel." There are several tabs on a complex dialog box. Take the "Sounds" tab. Somewhere on that tab there is a dropdown called "Sound Scheme" which lets you pick an auditory theme, just like your display can be given a visual theme. One of the options for a theme is "No Sounds." If that is what you have as your current selection, pick something else and then try again. You should always be able to pick "Windows Default" as a sound scheme.

There are tons of web sites that you can visit to download fanciful schemes, though you should ALWAYS have a good anti-virus program running if you are going to download anything. You used to be able to buy "cheapie" disks that contained 10 or 12 schemes but by now they are probably too cheap to make it worth burning the CD.
 

deletedT

Guest
Local time
Today, 07:16
Joined
Feb 2, 2019
Messages
1,218
VBA beep doesn't work if windows sound is set to No sound. If your settings in control panel is this, beep doesn't work. You have to change No sound to anything else.

2020-04-29_13-41-38.jpg
 

Users who are viewing this thread

Top Bottom