• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 685
  • Last Modified:

VBA Userform stops working after some time


I have a userform that i load from a control in an excel sheet.
It loads fine the first time and normally also a couple times more, but after some time, i will get the error 75(Path/File access error) "Could not find the specified object."

sub UITest is run from the control on the sheet, showing the form
sub  bGenerate_Click() is run from the form
Sub GenerateReport() is the sub that hides an unloads the form.

If I switch to the VBE after getting the error, I can show the code of the form, but i cannot show the form in the editor window

Anyone run into this before?
Sub UITest()
On Error GoTo ErrHandler:
Exit Sub
    'LogInformation Err.Number & " - " & Err.Description & " - " & Err.Source & " - " & Err.LastDllError
    LogInformation Format(Now, "yyyy-mm-dd hh:mm:ss") & ": @ UITest in Module3 " & " - " & Err.Number & " - " & Err.Description & " - " & Err.Source & " - " & Err.LastDllError
End Sub
Private Sub bGenerate_Click()
End Sub
Sub GenerateReport()
On Error GoTo ErrHandler:
    Dim m_Controller As Controller
    Set m_Controller = New Controller
    '... lines of code fetching the checkbox values from the form, ex.
    '...m_Controller.BVal = uWMain.CBAFG.Value
    Unload uWMain
    'Clean up
    Set m_Controller = Nothing
Exit Sub
    LogInformation Format(Now, "yyyy-mm-dd hh:mm:ss") & ": @ GenerateReport in Module3 & " - " & Err.Number & " - " & Err.Description & " - " & Err.Source & " - " & Err.LastDllError"
End Sub

Open in new window

1 Solution
It might be a problem in the form's code. I suggest that you remove the error handling, so that it breaks immediately on the failing line.
The only thing that I can think of is to assign your form to an object and then destroy the object at the end.  This should stop it getting stored in the memory

dim objuWMain as object

set objuWMain as new uWMain

'then load it up / show it ext and at the end just throw it away

set objuWMain = Nothing

Rory ArchibaldCommented:
I would also run Code Cleaner on your workbook if you haven't already. Available here: http://www.appspro.com/Utilities/CodeCleaner.htm
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

mortenbkAuthor Commented:
The error is from the command

Same error

It feels like the garbage collector removes the form-object

Err.Number: 75
Err.Description: Could not find the specified object.
Err.Source: Forms.Form.1
mortenbkAuthor Commented:
CodeCleaner done, same result, let it linger for 15 minutes and the object disappears
mortenbkAuthor Commented:
Guess I'll cloe this one myself...
 Never did find out what casues the crash, but if the whole shebang is run without the VBE open, it will not crash.... not that way anyways
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now