+ Reply to Thread
Results 1 to 8 of 8

Playing a sound file from VBA?

  1. Playing a sound file from VBA?

    Hi,
    I would like to be able to play a sound effect (eg, a .WAV file) under
    certain circumstances to alert the user to some event.

    What would be a good way to trigger playing the sound through VBA?

    TIA,
    Lyn.

  2. Re: Playing a sound file from VBA?

    Hi,

    > I would like to be able to play a sound effect (eg, a .WAV file) under
    > certain circumstances to alert the user to some event.
    >
    > What would be a good way to trigger playing the sound through VBA?


    Take a look at this :

    http://www.mvps.org/access/api/api0011.htm

    Regards
    Jens



  3. Re: Playing a sound file from VBA?

    On Mon, 30 Jul 2007 16:23:52 +0200, Jens Schilling wrote:

    > Hi,
    >
    >> I would like to be able to play a sound effect (eg, a .WAV file) under
    >> certain circumstances to alert the user to some event.
    >>
    >> What would be a good way to trigger playing the sound through VBA?

    >
    > Take a look at this :
    >
    > http://www.mvps.org/access/api/api0011.htm


    Thanks Jens, it looks like just what I want.

    Cheers,
    Lyn.

  4. Re: Playing a sound file from VBA?

    This is a follow-up to a question answered by Jens Schilling:

    On Mon, 30 Jul 2007 16:23:52 +0200, Jens Schilling wrote:

    >> What would be a good way to trigger playing the sound through VBA?

    >
    > Take a look at this :
    >
    > http://www.mvps.org/access/api/api0011.htm


    The code referred to works just fine (thanks!). However, it has exposed
    some unexpected behaviour. I am using it to play a simple sound (such as a
    "ding!") whenever a certain form is opened. I expected the sound and form
    opening to appear to occur simultaneously as observed by the user.

    Initially I ran the sound-playing API as part of the new form's Load event,
    but have also tried it in the Activate and Current events with no
    improvement.

    What is happening is this: Running the API plays the sound
    instantaneously. Opening the form without the API, the form appears on
    screen instantaneously. However, when opening the form and then playing
    the sound in the Load, Activate or Current events of that form, what
    happens is that the sound plays immediately, but the form does not appear
    on screen until after a 1-2 second delay.

    According to the VBA Help file, "The Activate event can occur only when a
    form or report is visible". So if I run the API from the Activate event,
    why does it not play the sound AFTER the form is visible (rather than delay
    the appearance of the form by 1-2 seconds)?

    Another question is, granted that the order of occurrence is reversed from
    what is expected (or at least, what *I* expected), why the delay after the
    sound is completed? Is it because the API is not sure when the sound is
    finished? Or because the sound file is longer than the endurance of the
    sound itself? The API does include an option to stop playing the sound,
    but since the sound lasts only a fraction of a second, I wouldn't know
    where to start to code this (I was really looking for a simple solution to
    what I thought was a simple problem!).

    Is there a way around this? I note that the MsgBox function, when using an
    option such as vbCritical, opens the message box form and plays the sound
    simultaneously, so it must be possible. I have tried using the same sound
    with my form but still the delay occurs.

    I don't mind a short delay after the sound plays, provided that the form is
    already opened -- the delay can be absorbed by the user's reaction time to
    the appearance of the form. So I guess the main question is: why does the
    sound delay the appearance of the visible form when the form should already
    be visible before the sound API is executed? Or have I got the
    functionality totally wrong ??

    Thanks for any help,
    Lyn.

  5. Re: Playing a sound file from VBA?

    did you try using the play mode of pcsASYNC, which tells it to not wait
    until the sound is finished playing?

    Lyn wrote:
    > This is a follow-up to a question answered by Jens Schilling:
    >
    > On Mon, 30 Jul 2007 16:23:52 +0200, Jens Schilling wrote:
    >
    >>> What would be a good way to trigger playing the sound through VBA?

    >> Take a look at this :
    >>
    >> http://www.mvps.org/access/api/api0011.htm

    >
    > The code referred to works just fine (thanks!). However, it has exposed
    > some unexpected behaviour. I am using it to play a simple sound (such as a
    > "ding!") whenever a certain form is opened. I expected the sound and form
    > opening to appear to occur simultaneously as observed by the user.
    >
    > Initially I ran the sound-playing API as part of the new form's Load event,
    > but have also tried it in the Activate and Current events with no
    > improvement.
    >
    > What is happening is this: Running the API plays the sound
    > instantaneously. Opening the form without the API, the form appears on
    > screen instantaneously. However, when opening the form and then playing
    > the sound in the Load, Activate or Current events of that form, what
    > happens is that the sound plays immediately, but the form does not appear
    > on screen until after a 1-2 second delay.
    >
    > According to the VBA Help file, "The Activate event can occur only when a
    > form or report is visible". So if I run the API from the Activate event,
    > why does it not play the sound AFTER the form is visible (rather than delay
    > the appearance of the form by 1-2 seconds)?
    >
    > Another question is, granted that the order of occurrence is reversed from
    > what is expected (or at least, what *I* expected), why the delay after the
    > sound is completed? Is it because the API is not sure when the sound is
    > finished? Or because the sound file is longer than the endurance of the
    > sound itself? The API does include an option to stop playing the sound,
    > but since the sound lasts only a fraction of a second, I wouldn't know
    > where to start to code this (I was really looking for a simple solution to
    > what I thought was a simple problem!).
    >
    > Is there a way around this? I note that the MsgBox function, when using an
    > option such as vbCritical, opens the message box form and plays the sound
    > simultaneously, so it must be possible. I have tried using the same sound
    > with my form but still the delay occurs.
    >
    > I don't mind a short delay after the sound plays, provided that the form is
    > already opened -- the delay can be absorbed by the user's reaction time to
    > the appearance of the form. So I guess the main question is: why does the
    > sound delay the appearance of the visible form when the form should already
    > be visible before the sound API is executed? Or have I got the
    > functionality totally wrong ??
    >
    > Thanks for any help,
    > Lyn.


  6. Re: Playing a sound file from VBA?

    On Sat, 04 Aug 2007 12:49:41 -0800, John Welch wrote:

    > did you try using the play mode of pcsASYNC, which tells it to not wait
    > until the sound is finished playing?


    I completely missed that! However, I have now tried it and it does resolve
    my problem. Thank you!

    >> According to the VBA Help file, "The Activate event can occur only when a
    >> form or report is visible". So if I run the API from the Activate event,
    >> why does it not play the sound AFTER the form is visible (rather than delay
    >> the appearance of the form by 1-2 seconds)?


    I am still curious about this, but now that the sound delay problem has
    been resolved, it has become merely academic.

    Thanks again.

    Cheers,
    Lyn.

  7. Re: Playing a sound file from VBA?

    Lyn, I'm glad that worked for you. As for the other thing, I'm not sure,
    but I think they mean that if you set the form's visible property to
    false, as in:
    forms!frmSomeForm.visible=false

    then that form won't be able to be activated.
    -John

    Lyn wrote:
    > On Sat, 04 Aug 2007 12:49:41 -0800, John Welch wrote:
    >
    >> did you try using the play mode of pcsASYNC, which tells it to not wait
    >> until the sound is finished playing?

    >
    > I completely missed that! However, I have now tried it and it does resolve
    > my problem. Thank you!
    >
    >>> According to the VBA Help file, "The Activate event can occur only when a
    >>> form or report is visible". So if I run the API from the Activate event,
    >>> why does it not play the sound AFTER the form is visible (rather than delay
    >>> the appearance of the form by 1-2 seconds)?

    >
    > I am still curious about this, but now that the sound delay problem has
    > been resolved, it has become merely academic.
    >
    > Thanks again.
    >
    > Cheers,
    > Lyn.


  8. Re: Playing a sound file from VBA?

    On Sun, 05 Aug 2007 10:01:19 -0800, John Welch wrote:

    > As for the other thing, I'm not sure, but I think they mean that if you set
    > the form's visible property to false, as in:
    > forms!frmSomeForm.visible=false
    >
    > then that form won't be able to be activated.


    >>>> According to the VBA Help file, "The Activate event can occur only when a
    >>>> form or report is visible". So if I run the API from the Activate event,
    >>>> why does it not play the sound AFTER the form is visible (rather than delay
    >>>> the appearance of the form by 1-2 seconds)?

    >>
    >> I am still curious about this, but now that the sound delay problem has
    >> been resolved, it has become merely academic.


    That's another interpretation of the quote. And in fact, on reflection I
    think that you are probably right. Anyway, I will take that as answering
    my curiosity!

    Thanks again,
    Lyn.

+ Reply to Thread