473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Add sound when subtracted value = 0 in subform

547 512MB
I have a timing program. My one client want's a new feature.
The cyclist do laps. The number of laps are predetermined ie 2. When the rider completed the 2 laps, i subtract the original number (2) from number of laps completed ie 2, and if its 0(zero) the person is finish.
When this quantity is 0, i want a beep sound to go off. I get it right, but it then also beep should i press the refresh button or go in and out of screen.
Code is in "on current"
Expand|Select|Wrap|Line Numbers
  1. Dim iRetValue As Long
  2.   If me.Lapsremain = 0 then iRetValue = sndPlaySound(CurrentProject.Path & "\beep6.wav", SND_ASYNC)
I need it to only beep when a new record is added and the subtraction value comes to =0 This value is displayed in a subform (RaceresultsSF) next to the subform (RaceTimingSF) where capturing is done.
Please see the attached picture so see where the zero is displayed.

any suggestions

Attached Images
File Type: jpg laps0.jpg (99.3 KB, 567 views)
May 1 '11 #1

✓ answered by neelsfer

Got it right after i copy and pasted the code into many different events.
Eventually I put this code into "After insert" event of specific form and it worked
It first updated the other subform and then checked for 0 or 1 in lapsremain field, followed by sound.
Expand|Select|Wrap|Line Numbers
  1. # [Forms]![racesetupXCf]![RaceresultsSF].Requery
  2. # If [Forms]![racesetupXCf]![RaceresultsSF]![LapsRemain] = 1 Then iRetValue = sndPlaySound(CurrentProject.Path & "\bell.wav", SND_ASYNC) Else
  3. # If [Forms]![racesetupXCf]![RaceresultsSF]![LapsRemain] = 0 Then iRetValue = sndPlaySound(CurrentProject.Path & "\bleep4.wav", SND_ASYNC)
Thx TheSmileyCoder, you put me on the right track

9 2342
TheSmileyCoder
2,322 Expert Mod 2GB
The problem comes from using the in-correct event. The On-Current is fired when moving between records or to a new record. You probably need to use either the Forms AfterUpdate/BeforeUpdate, or possibly a textbox' before/after update. It depends on how you input the laps I suppose.
May 1 '11 #2
neelsfer
547 512MB
I have tried all options.
I get the wav files to play when you have 1 lap or 0 laps left, but it continue thereafter to beep if you press refresh or go in or out of screen.
the code i used is in "on enter" in racenumber field in RaceTimingSF subform.
Expand|Select|Wrap|Line Numbers
  1. Dim iRetValue As Long
  2. [Forms]![racesetupXCf]![RaceresultsSF].Requery
  3. If [Forms]![racesetupXCf]![RaceresultsSF]![LapsRemain] = 1 Then iRetValue = sndPlaySound(CurrentProject.Path & "\bell.wav", SND_ASYNC) Else
  4.  
  5. If [Forms]![racesetupXCf]![RaceresultsSF]![LapsRemain] = 0 Then iRetValue = sndPlaySound(CurrentProject.Path & "\bleep4.wav", SND_ASYNC)
The requery above is used to update another subform on the same screen with calculated times
see attached example and read instructions on screen pls.
please help
Attached Files
File Type: zip RacetimingFinish2003.zip (1.07 MB, 102 views)
May 2 '11 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Well I've spend quite a bit of time looking at your database, but to be honest its simply to messy for me to spend more time on. Half the comments are just old that you have commented out, I have no idea what to makes heads or tails off.

Only thing I can say is that the ENTER event is NOT the correct event to use, since it will fire each you enter the record and that does not seem to be what you want. However since your basing your testing of whether or not to play the sound on a field in another form, you have to take that into account. The AfterUpdate of the control will not work, unless you use the same event to update the other form. (Before doing your check)
May 2 '11 #4
neelsfer
547 512MB
thx TheSmileyCoder so far.
I get it to work but is seems to continue to repeat the last sound produced when the lapsremain field in the RaceresultsSF subform was either 0 or 1, when i press refresh or enter the form from another.
I have just given you important parts of the application and deleted a lot of the buttons and functions before posting it, to reduce the size.

i think the problem is in the racenumber field of the RaceTimingSF subform when pressing enter, with this code
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False
  2. [Forms]![racesetupXCf]![RaceresultsSF].Requery
  3. If [Forms]![racesetupXCf]![RaceresultsSF]![LapsRemain] = 1 Then iRetValue = sndPlaySound(CurrentProject.Path & "\bell.wav", SND_ASYNC) Else
  4. If [Forms]![racesetupXCf]![RaceresultsSF]![LapsRemain] = 0 Then iRetValue = sndPlaySound(CurrentProject.Path & "\bleep4.wav", SND_ASYNC)
  5. KeyAscii = 0
  6. Cancel = True
Sorry I forgot to include another 2 sound files. Create a directory called c:\rt and copy these 2 attached files into there, together with main application file.You can then hear the sound problem.
Attached Files
File Type: zip Bell.zip (103.2 KB, 96 views)
May 2 '11 #5
neelsfer
547 512MB
Got it right after i copy and pasted the code into many different events.
Eventually I put this code into "After insert" event of specific form and it worked
It first updated the other subform and then checked for 0 or 1 in lapsremain field, followed by sound.
Expand|Select|Wrap|Line Numbers
  1. # [Forms]![racesetupXCf]![RaceresultsSF].Requery
  2. # If [Forms]![racesetupXCf]![RaceresultsSF]![LapsRemain] = 1 Then iRetValue = sndPlaySound(CurrentProject.Path & "\bell.wav", SND_ASYNC) Else
  3. # If [Forms]![racesetupXCf]![RaceresultsSF]![LapsRemain] = 0 Then iRetValue = sndPlaySound(CurrentProject.Path & "\bleep4.wav", SND_ASYNC)
Thx TheSmileyCoder, you put me on the right track
May 3 '11 #6
NeoPa
32,556 Expert Mod 16PB
Excuse me if I'm off-base here, but it seems you have a trigger which determines when a state is active, when really you need a trigger which determines when a state has been reached. The difference being that it only causes the sound once. When the state is reached, rather than every time a particular piece of code is encountered once that state has been reached (X <= 0 or whatever).

To ensure a sound only gets triggered once, it makes sense to set a boolean variable to indicate when it has been triggered already. So, for instance, if X <= 0 is the triggering logic, and the new boolean variable is blnY, then this would change to X <= 0 AND Not blnY. The code that is triggered must still make the required sound, but it would have an extra task of setting blnY to True. That way it would only be run the once.

This fundamental logic could be manipulated if the logic needs to allow for the process to run again or any other complications, but the basic logic should be sound.
May 3 '11 #7
neelsfer
547 512MB
thx Neopa. It sounds like the correct way to do it. For now with my limited knowledge, i seemed to got it working by luck, by changing the event from where its fired from.Took me 2 solid days however.
May 3 '11 #8
NeoPa
32,556 Expert Mod 16PB
I can't say for sure without a better appreciation of your exact issue, but sometimes triggering it in a different way obviates the requirement for programming the extra logic, so don't feel you've necessarily found a less good solution. At least it's another option should you need it, which is always handy to have in your locker.

The important point really is that you have found a solution.
May 4 '11 #9
TheSmileyCoder
2,322 Expert Mod 2GB
If you want to learn more about the events and when and in what order they fire, a simple approach is to make code for each event containing a msgbox, with the event's name. For example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate()
  2.   MsgBox "Form_BeforeUpdate"
  3. end Sub
Then you can accurately determine in which order they fire, and also possibly what the correct event to use is. (After_Insert sounds like a good event to use in your case.)
May 4 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mike | last post by:
Am I correct in assuming that when the starting value of a select list is re-selected, the onChange command does not execute? I need to have it execute when the original value is selected if...
2
by: Mike Minor | last post by:
I have a request from a client to play a sound when a specific <input type=text> field has been updated with new data from a server side script. They have not specified the sound ( yet ), so I'm...
4
by: Rodger Dusatko | last post by:
In VB .NET I am having problems setting breaks. I want the break to be independant of any single function: for example: err.number or global variables When I try to set a break with the 'Data'...
2
by: patrick | last post by:
I have the following code in ASP.NET 2.0 (C#) DateTime datStartDate; datStartDate = calMonth.SelectedDate; //calStart is a calendar control datStartDate = datStartDate.AddDays(-6); and it...
16
by: Chris Ianson | last post by:
Hi, is there a way to play a small sound snippet when a user clicks a certain hyperlink hotspot on an image? Thanks in advance.
1
by: Pieter | last post by:
Hi, Is there a way to link the Hidden-property of a Textbox on a Reporting Services Report to it's Value? When the Value is empty (""), then I want the TextBox be Hidden. In case you don't...
3
by: Bill | last post by:
I have a report with a text box named Discount. If this text box shows a value of 0, I do not want the text box to be visible. I have tried the following code, but it disables the control even...
3
by: ramya naidu | last post by:
Hai iam working on a project were i have some textboxes in that one textbox should allow only digits from 0 to 360 and for that i have a error provider when i enter 361 the error provider blinks i...
2
by: jiayanxiang | last post by:
Is there some way to programmatically turn off the "Ding" sound when the user presses Enter in a text field?
4
by: mfaisalwarraich | last post by:
Hi everybody, I have some problem so need some help. wat im trying to do is making a function which will change the value of a input field when the value of other input field is changed. im using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.