Connecting Tech Pros Worldwide Forums | Help | Site Map

OLE object wav

Member
 
Join Date: Mar 2008
Posts: 114
#1: Oct 7 '09
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?
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Me.txtoffer.SetFocus
  3. phone.Action = acOLEActivate
  4. End Sub
  5.  
  6. Private Sub Form_Timer()
  7. Me.TimerInterval = 0
  8. thinking.Action = acOLEActivate
  9. End Sub
Thanks in advance!

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#2: Oct 7 '09

re: OLE object wav


Are you asking how to stop your sound from continuing, or are you asking how the code can run when the form is closed?
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,175
#3: Oct 7 '09

re: OLE object wav


You can always put a Close button on your form.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#4: Oct 7 '09

re: OLE object wav


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 :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.Close
This way all methods of closing are equally well captured.
Member
 
Join Date: Mar 2008
Posts: 114
#5: Oct 7 '09

re: OLE object wav


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.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "SwitchBoard"     (this is actually minimized)
  2. DoCmd.Close acForm, "Dond"
This is called when the user clicks a button
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#6: Oct 7 '09

re: OLE object wav


Quote:

Originally Posted by Jollywg View Post

I apologize for not correctly organizing my post...its been a while.

Fair enough. That makes sense.
Quote:

Originally Posted by Jollywg View Post

here is how i am closing it.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "SwitchBoard"     (this is actually minimized)
  2. 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.
Quote:

Originally Posted by Jollywg View Post

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.
Member
 
Join Date: Mar 2008
Posts: 114
#7: Oct 8 '09

re: OLE object wav


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().

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Me.txtoffer.SetFocus
  3. phone.Action = acOLEActivate    'not the sound i'm wanting to stop. only lasts 5 sec)
  4. End Sub
  5.  
  6. Private Sub Form_Timer()
  7. thinking.Action = acOLEActivate  'sound is a rather long wav file that i need to stop if the user closes the form
  8. End Sub
  9.  
  10. Private Sub NoDeal_Click()
  11. DoCmd.OpenForm "SwitchBoard"
  12. DoCmd.Close acForm, "Dond"
  13. End Sub
  14.  
Thank you for your patience
Jollywg
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#8: Oct 8 '09

re: OLE object wav


Quote:

Originally Posted by Jollywg View Post

I apologize for being unclear, but hopefully we can start to solve the issue...below is all of my code for the form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer()
  2. thinking.Action = acOLEActivate  'sound is a rather long wav file that i need to stop if the user closes the form
  3. 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.
Member
 
Join Date: Mar 2008
Posts: 114
#9: Oct 11 '09

re: OLE object wav


Sorry I havn't responded...been 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?
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#10: Oct 12 '09

re: OLE object wav


I know of no way, but I've put out a call for help on the WAV object. Let's see what appears.
Member
 
Join Date: Mar 2008
Posts: 114
#11: Oct 12 '09

re: OLE object wav


I appreciate it, thanks NeoPa!
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 788
#12: Oct 16 '09

re: OLE object wav


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
Expand|Select|Wrap|Line Numbers
  1. Dim Thinking as Control
  2. ...
  3. Set Thinking=blah blah blah
  4.  
You need to have done something like that in order to use it in your forms timer event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Timer() 
  2.    thinking.Action = acOLEActivate  
  3. End Sub 
  4.  
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
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close() 
  2.    set thinking=nothing
  3. End Sub 
  4.  
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
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close() 
  2.    thinking.Action = acOLEDeActivate  
  3. End Sub 
  4.  
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.
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 788
#13: Oct 16 '09

re: OLE object wav


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

acOLEClose
Member
 
Join Date: Mar 2008
Posts: 114
#14: Oct 16 '09

re: OLE object wav


I've tried the acOLEClose and it unfortunately doesnt work, but I will give your previous post a try.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#15: Oct 16 '09

re: OLE object wav


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).
Reply

Tags
acole, object, ole, sound, wav