WindowsMediaPlayer control causes crash on DoCmd.Close



I have a form with two WebBrowser controls and a WindowMediaPlayer control.
I also have a "cancel" button which simply invokes DoCmd.Close. If I hit the
red "X" on the title bar, there are no problems. However, if I hit the
cancel button, access crashes without fail. It seems to happen after the
actual call to DoCmd.Close. A google search showed someone else who has
experienced this behavior:

So far I have not found any solutions.

Your help is much appreciated,
Dec 11, 2015
Reaction score
This thread date is pretty old, but i just had this same problem now in 2015 and couldn't find a solution on the web. However i was able to figure one out that worked in my instance and maybe it can help others too.

I had a form with an active-x webbrowser control on it and it kept crashing when it closed, but it didn't do it under all conditions or when i closed the window with the "x" button rather than vba. It took a while to narrow down but i was able to attribute the crash to the webbrowser part and eventually evidence pointed to a timing issue with the Access VBA commands and something about the web browser control's present state. i really don't know exactly why it was crashing, but treating it as a timing issue and browser content state i found the following code fixed my problem.

Set the webbrowser's url to "about:blank", then keep checking until the browser has actually set the new blank state before executing the close command. Wait is a custom function, not built in (included below). The webbrowser control's name is "webTemplateBrowser", the form is "NotebookManager". This code is part of other code within a button click event. I added count really just to check if it ever actually entered the loop which would mean that the browser control had not finished it's navigation action immediately, and thus confirm that the browser control can be in a state of executing one action while the VBA code has moved on and potentially running other commands that could conflict with it. and it does enter the loop at least once so if it had executed the close command next instead of the loop it would be doing so while the webbrowser control was in an intermediate state of some kind.

Dim count as Integer
count = 0
Me.webTemplateBrowser.Navigate2 "about:blank"
Do While webTemplateBrowser.LocationURL <> "about:blank"
Wait 0.2
count = count + 1
Debug.Print "countweb" & count
DoCmd.Close acForm, "NotebookManager", acSaveNo

The wait sub:

Sub Wait(sngTimeToWait As Single) 'sngTimeToWait is in seconds
If gcfHandleErrors Then
On Error GoTo PROC_ERR
End If

Dim TimeInterval As Single
TimeInterval = Timer
Do Until Timer >= (TimeInterval + sngTimeToWait)

Exit Sub
MsgBox "Error: (" & Err.Number & ") " & Err.Description & ": GeneralSubs-Wait", vbCritical
End Sub

Hope this helps the next person that might be having weird crashes mixing active-x controls and VBA.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question