Results 1 to 13 of 13
  1. #1
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368

    play sound upon change

    Guys,

    i have created a monitoring tool that sees if the modem of a certain building responds, or not.
    That wasnt really hard to do, Just used the forms timer to execute a ping and based on the return ("" or <> "")
    the form displays an "online" or "offline" label.

    The monitoring tool is worthless however if the computer can't play a sound when the status changes.
    As labels arent the best for these purposes ive created a control that changes to "yes" or "no" when the status of the modem changes.

    I figured i could use the _change event procedure of the control to trigger the sound. But whatever i do the sound wont play !

    The change event should be triggered when the data the control holds changes and i see the text changing but no sound. The sound itself works, ive tested this offcouse.

    Am i overlooking something ?



    Pls help, spend all night trying to solve this and my head is about to explode !

    Code:
    Private Sub fldChange_Change()
    
    
    Dim iRetValue As Long
    iRetValue = sndPlaySound("C:\Program Files\Microsoft Lync\Media\COMMUNICATOR_presence", SND_ASYNC)
    
    
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Is this source of your code http://www.cpearson.com/excel/PlaySound.aspx

    What is the name of the sound file? I don't see a file extension.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Yeah, no file described within that code.

    I never tried using winmm.dll to play WAV files before. I always thought it was limited to midi files. I guess the trick is putting the file in the Media folder. I wonder if windows media player runs in the background.

  4. #4
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    If i make a button and i click it the sound plays. So its not the sound thats the problem.
    Somehow the change event doesnt fire and im clueless why.
    In the discription of the _change event it says that when the data in the field changes the event is triggered.
    The data clearly and visibly changes from yes to no.
    At first i thought it was because the control wasnt bound to a field in my table. But thats not the case either.
    When i trigger the event on form timer it plays as well. But then it plays every time the ping is send out, so thats not what i want.
    I want the sound to play when the status of the object changes.

    And yes, im curious to se if the sound plays in the background, but lets get the sound to work first

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Possibly Change event only triggers with typing or clicking input.

    Try AfterUpdate event.

    Maybe should have code in the procedure that sets the control to yes/no.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Ive tryed afterupdate, and another related event as well. Im going to work in an hour and try again. Any other suggestions or workarounds are greatly appreciated !

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I just tested code in AfterUpdate event of unbound textbox. It works only if I type into the textbox, not if value is programmatically changed. Same for Change event.

    Again, suggest you put call to the sndPlaySound32 function in the procedure that changes the value of control.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Hi June, many thanks for testing it.
    Seems your are rigtht, but i cant call it from the procedure that changes the value of the control.
    This is because the procedure is fired constantly. It would mean the sound would play every time of the interval of the form timer.
    I want it to play the sound ONLY when the value changes from "" to <>"" or the other way around.
    This is why i created the textbox, as a workaround.
    Since i now bound the control to a field in my table im gonna try fire the code with the Dirty function of the form.
    If that doesnt work, im gonna sue Microsoft..

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    maybe refresh the control and use the after update to trigger code???

  10. #10
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Like June said Access doesnt recoqnise if the field has been updated programmaticly. So im guessing a refresh doesnt work.
    Even a form_dirty event doesnt trigger it.

    It isnt rocket science to look if a value has been changed, so why is this so hard ?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Only other possibility I can think of is form BeforeUpdate or AfterUpdate.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    As with the afterupdate event of the form, the sound plays when i exit the (updated) form..
    If the form isnt updated then the sound doesnt play.

    So my (custom made) exit form button sees the form is changed..

    Ive tryed me.form.refresh and then the sound does play, but also with every interval of form timer.

    im going berserk

  13. #13
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Right i got it solved !

    I made two controls on my form :

    ctrlOnline
    ctrlOffline

    When the forms timer returns <> "" on strPing i move the focus to ctrlOnline
    When the forms timer returns "" on strPing i move the focus to ctrlOffline

    I set the _GotFocus() of both controls to play the sound.

    So when the modem is online the focus is kept on ctrlOnline, and when the forms timer "sees" the modem is offline
    the focus is moved to ctrlOffline and thus plays a sound.
    And vice versa offcourse.

    I have set the width of both controls to 0 so they appear invisible.

    The only issue i have is when i first click the button that starts the monitoring of the modem the focus is set to
    either ctrlOnline or ctrlOffline and plays the sound once while it should not.
    After that initial sound it works perfect !

    thanks for thinking with me guys, much appreciated !

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Play sound until button is released
    By ino_mart in forum Programming
    Replies: 1
    Last Post: 11-09-2011, 04:44 PM
  2. sound notifications
    By TheShabz in forum Access
    Replies: 7
    Last Post: 08-31-2010, 08:54 PM
  3. Word Play example
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-30-2010, 11:11 PM
  4. inserting .wav sound?
    By dada in forum Programming
    Replies: 2
    Last Post: 08-20-2010, 11:25 PM
  5. how to play mp3 direct from database
    By sean in forum Access
    Replies: 0
    Last Post: 10-20-2009, 08:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums