OLE object wav

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jollywg
    New Member
    • Mar 2008
    • 158

    OLE object wav

    I have a OLE object that is a wav file and it plays whenever a form is opened. The only catch is that I need it to stop playing when the form is closed. Right now I am having to press the 'esc' key. I've tried using sendkeys, but it doesn't work. Any ideas?
    Code:
    Private Sub Form_Load()
    Me.txtoffer.SetFocus
    phone.Action = acOLEActivate
    End Sub
    
    Private Sub Form_Timer()
    Me.TimerInterval = 0
    thinking.Action = acOLEActivate
    End Sub
    Thanks in advance!
    Last edited by NeoPa; Oct 7 '09, 07:57 PM. Reason: Please use the [CODE] tags provided.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32656

    #2
    Are you asking how to stop your sound from continuing, or are you asking how the code can run when the form is closed?

    Comment

    • ChipR
      Recognized Expert Top Contributor
      • Jul 2008
      • 1289

      #3
      You can always put a Close button on your form.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32656

        #4
        I always recommend using the Form_Close() event procedure, in place of any specific Close button, to handle closing logic. This certainly doesn't mean not to provide one, simply that the only code in there should be :
        Code:
        Call DoCmd.Close
        This way all methods of closing are equally well captured.

        Comment

        • Jollywg
          New Member
          • Mar 2008
          • 158

          #5
          I apologize for not correctly organizing my post...its been a while.
          here is how i am closing it. To answer your question NeoPa i am wanting to stop the audio file after it has played and when the form closes.
          Code:
          DoCmd.OpenForm "SwitchBoard"     (this is actually minimized)
          DoCmd.Close acForm, "Dond"
          This is called when the user clicks a button

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32656

            #6
            Originally posted by Jollywg
            I apologize for not correctly organizing my post...its been a while.
            Fair enough. That makes sense.
            Originally posted by Jollywg
            here is how i am closing it.
            Code:
            DoCmd.OpenForm "SwitchBoard"     (this is actually minimized)
            DoCmd.Close acForm, "Dond"
            This is called when the user clicks a button
            You don't include the wrappings so it's impossible to tell which event it is within. I suspect (from what you say) that it is within the Click event procedure of a CommandButton. It would be nice to be sure, especially as I've just posted explaining why closing forms code should never be held there.
            Originally posted by Jollywg
            To answer your question NeoPa i am wanting to stop the audio file after it has played and when the form closes.
            Unfortunately, that doesn't actually answer my question.

            Here it is again :
            Are you asking how to stop your sound from continuing, or are you asking how the code can run when the form is closed?

            If that's not clear, then I'm asking if you need to know how to code it to stop the noise, or where you would need to put that code (assuming you already have it) to ensure it's run when the form is closed.

            Comment

            • Jollywg
              New Member
              • Mar 2008
              • 158

              #7
              I apologize for being unclear, but hopefully we can start to solve the issue...below is all of my code for the form. I've put notes out to the side to give a little more detail as to what is going on. I'm needing to stop the sound when the form is closed. I have no idea as to how to do this, but I would imagine that the code would be placed in the form_colse() or in the NoDeal_Click().

              Code:
              Private Sub Form_Load()
              Me.txtoffer.SetFocus
              phone.Action = acOLEActivate    'not the sound i'm wanting to stop. only lasts 5 sec)
              End Sub
              
              Private Sub Form_Timer()
              thinking.Action = acOLEActivate  'sound is a rather long wav file that i need to stop if the user closes the form
              End Sub
              
              Private Sub NoDeal_Click()
              DoCmd.OpenForm "SwitchBoard"
              DoCmd.Close acForm, "Dond"
              End Sub
              Thank you for your patience
              Jollywg

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32656

                #8
                Originally posted by Jollywg
                I apologize for being unclear, but hopefully we can start to solve the issue...below is all of my code for the form.
                Code:
                Private Sub Form_Timer()
                thinking.Action = acOLEActivate  'sound is a rather long wav file that i need to stop if the user closes the form
                End Sub
                I wish it were that easy. I needed to know which you were after because I know I can't help with the code to stop the sound. Only with where best to put it (In Form_Close() as you quite correctly say).

                There is nothing in your posted code that tells me what type of object it is that you call thinking. I'm sure it's OLE related (not an area I'm strong in I'm afraid), but beyond that I have no clues. Certainly, if I can help at all here, it would be to advise searching for information related to that OLE object type. It may be (unless you know otherwise) that stopping the sound is not even supported. I don't know.

                If you can post what you know about the object (Remember, the class name alone may not be enough) then I can certainly attempt to have a look around for you, but I can't promise anything. As I say, this is new territory for me too.

                Comment

                • Jollywg
                  New Member
                  • Mar 2008
                  • 158

                  #9
                  Sorry I havn't responded...bee n out of town. I'm absolutely no good at OLE either, all I know is that its a wav object. Is there another way to play a sound and stop it in Access?

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32656

                    #10
                    I know of no way, but I've put out a call for help on the WAV object. Let's see what appears.

                    Comment

                    • Jollywg
                      New Member
                      • Mar 2008
                      • 158

                      #11
                      I appreciate it, thanks NeoPa!

                      Comment

                      • Delerna
                        Recognized Expert Top Contributor
                        • Jan 2008
                        • 1134

                        #12
                        Not my strong point either but lets see if I can offer something of value.

                        Somewhere in your code you are creating the "Thinking" object....right ?
                        something like
                        [code=vba]
                        Dim Thinking as Control
                        ...
                        Set Thinking=blah blah blah
                        [/code]

                        You need to have done something like that in order to use it in your forms timer event.

                        [code=vba]
                        Private Sub Form_Timer()
                        thinking.Action = acOLEActivate
                        End Sub
                        [/code]

                        which starts the sound playing

                        So I am wondering if you destroy the thinking object in the form close event, then that might stop the sound.
                        Something like this
                        [code=vba]
                        Private Sub Form_Close()
                        set thinking=nothin g
                        End Sub
                        [/code]

                        You might need to add some code that checks if thinking still exists
                        before you destroy it.

                        If that dosn't work then I would imagine you will need something like
                        [code=vba]
                        Private Sub Form_Close()
                        thinking.Action = acOLEDeActivate
                        End Sub
                        [/code]

                        I don't know if acOLEDeActivate is correct or not, I will let you find the
                        constant that does the opposite of acOLEActivate.
                        I would imagine a search in Google would find thousands of matches

                        I hope this helps.

                        Comment

                        • Delerna
                          Recognized Expert Top Contributor
                          • Jan 2008
                          • 1134

                          #13
                          Actually, you got my interrest peaked.
                          I just did a quick search and found a potential candidate

                          acOLEClose

                          Comment

                          • Jollywg
                            New Member
                            • Mar 2008
                            • 158

                            #14
                            I've tried the acOLEClose and it unfortunately doesnt work, but I will give your previous post a try.

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32656

                              #15
                              JollyWg,

                              It would be helpful for anyone trying to research your problem if you posted both the code that declares these objects and the code that sets them up. Otherwise we're all trying to work with our hands tied behind our backs.

                              I referred to this earlier if you remember (post #8).

                              Comment

                              Working...