Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emulating the Inkey$ function in Access

Status
Not open for further replies.

StuGreentree

IS-IT--Management
Dec 31, 2001
8
0
0
US
I am currently adding a visual & audible alarm to a form I have created. The alarm is event driven and I am searching for a way to turn it off. I have tried both the getKeyState and GetAsyncKeyState, but it will not respond to either except in Debug Mode. I have enclosed the general code I have been using to invoke the alarm. Any help would be appreciated. Thanks.....]

Private Sub Text0_KeyPress(KeyAscii As Integer)
Dim Keystate As Integer, Flag as Boolean
Flag = True
Do While Flag
Text0.Value = "ALERT!!! Account is Overdrawn"
Text0.BackColor = RGB(255, 0, 0)
Text0.ForeColor = RGB(0, 0, 0)
Call PlaySound("Sprngbng.wav", 0, &H1)
Me.Repaint
For Y = 1 To 7000000: Next Y
Text0.BackColor = RGB(192, 192, 192)
Text0.ForeColor = RGB(255, 0, 0)
Me.Repaint
For Y = 1 To 7000000: Next
Keystate = GetAsyncKeyState(vbKeySpace)
If Keystate > 0 Then
Flag = False
End If
Loop
End Sub
 
StuGreentree,

Can you show me the code in the routine PlaySound ?

For me to to provide you a simple solution
 
Playsound is a Windows API call using the following context...
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Therefore the first value is obvious "Pathstring & Filename, sorry I don't remember the function of the second parameter (usually 0), the third value is the HEX equivilant for Asyncronous Sound (sound can be launched again before finishing)
 
After the "Loop" statement add the following statement

Call PlaySound("", 0, SND_PURGE Or SND_NODEFAULT) ' stop playback
 
Whoops missed this bit of info earlier :
the Loop is checking if you have hit the space bar key
which will also keep the music playing continuously.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top