From: joel on

I think I found the problem. I set bIsLoaded = False in the function
below. Without this statement the function was returing nothing which
may of caused problems with your code.




Function IsFormLoaded(sFrmName As String) As Boolean
Dim i As Long
Dim bIsLoaded As Boolean
bIsLoaded = False

For i = 1 To UserForms.Count
If UserForms(i - 1).Name = sFrmName Then
bIsLoaded = True
Exit For
End If
Next
IsFormLoaded = bIsLoaded
End Function


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=165579

[url="http://www.thecodecage.com"]Microsoft Office Help[/url]

From: Robert Crandal on
Hi Joel. Thanks for catching that minor function flaw.
Unfortunately, my workbook is still crashing with a Run Time
Error 75 because my Userform1 object seems to keep
vanishing.

I have stripped down my code to only the following which
is placed in my Userform1 code module.
-------------------------------------------------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_HWNDPARENT As Long = -8
------------------------------------------------------------------------------
Private Sub UserForm_Initialize()
Dim hWnd As Long
hWnd = FindWindow("ThunderDFrame", Me.Caption)
SetWindowLongA hWnd, GWL_HWNDPARENT, 0&
End Sub
-------------------------------------------------------------------------------
' Module 1
Sub Button1_Click()
Userform1.Show vbModeless
End Sub
------------------------------------------------------------------------------

The problem seems to be the "SetWindowLongA" function call which changes the
window style to GWL_PARENT.

I know that if I get rid of this call to SetWindowLongA that my Userform1
will
never disappear at random times, but I really love having this special popup
window
that remains visible even when Excel is minimized.

Also, the above code works fine on my Windows Vista machine. It only
crashes
on Windows XP, Service Pack 2. Try loading the userform a couple times,
walk away from your computer for about 2-5 minutes after the screen saver
turns
on, then try to load the userform again. That is when I get the message
"Could not find the specified object"

How about if I set the Userform flag back to it's original setting when the
user
closes out or unloads the form??? In other words, how can I change the
window flag from GWL_HWNDPARENT back to it's original setting???
I'm not sure how I would do that??



"joel" <joel.43z7zq(a)thecodecage.com> wrote in message
news:joel.43z7zq(a)thecodecage.com...
>
> I think I found the problem. I set bIsLoaded = False in the function
> below. Without this statement the function was returing nothing which
> may of caused problems with your code.
>

From: joel on

I'm using XP SP3 (not 2) with Office 2003 and not having the problem.
My Monitor is set to 800 x 600.

I verified my SP3 by going to control panel and selecting Add/Remove
Programs. At the end of the list of installed software is Windows XP
Service Pack 3.


I also chaeck the version of windows by getting a DOS window (cms.exe).
the top of the DOS window show 5.1.2600. I upgrade a couple weeks ago
manually so the exact numbers may not match.


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=165579

[url=&quot;http://www.thecodecage.com&quot;]Microsoft Office Help[/url]

From: Dave Unger on
Hi Robert,

I started having similar problems quite recently (Run Time Error
75" ("Could Not Find The Specified Object"), seems to happen
sporadically when vba is trying to reference a form - doesn't seem to
limited to one particular form. I have a vague (very) notion that
there is an "orphaned" form object, caused by halting the code during
development. Also, whenever this happens, Excel will crash if I try
to save the application. This has been happening with increasing
frequency, and is quite frustrating. I'm running Winsows XP SP3 and
XL2007.

I'm just wondering if you've found the cause/solution to this yet.

regards,

Dave



On Dec 28 2009, 11:33 pm, "Robert Crandal" <nob...(a)gmail.com> wrote:
> This is follow-up related to my posting here on 12/19/09
> regarding "Run Time Error 75" ("Could Not Find The
> Specified Object".
>
> Basically, my Userform1 is "disappearing" from my workbook
> for some unknown reason, even if my workbook is untouched
> for any period of time longer than 2 minutes.  If I come back to
> my computer after 2 minutes, I will try to load myformwith this
> code:   (which causes RT-Error 75)
>
>                  UserForm1.Show vbModeless  
>
> I also get an Error 75 message if I try to run the following code:
>
>           MsgBox "Name ofform: " & UserForm1.Name
>
> Then, if I try to view my UserForm1 object in my VBAProject
> view window, I get an error that says "Path/File sccess Error".
>
> Does anybody have any theories why I cannot suddenly use
> Userform1 in my workbook, especially if my code is not very
> complicated at all??   All I do is handle UserForm1_Initialize()
> and Worksheet_Change() and all my code does is transfer
> data from userform to spreadsheet and vice versa with very
> very very basic VBA code.  I even set "Application.EnableEvents"
> to false and true inside my Worksheet_change() function.
>
> Could this be just an operating system issues??  (I noticed
> that this problem only occurs while using Excel 2007
> (Trial Version) on Windows XP Professional SP2.  I never get
> this error on Windows Vista using Excel 2007)
>
> Might this problem just be related to a bad or bugged version
> of Windows XP, Service Pack 2???   Ican'tthink of anything else.
>
> thank you!

From: Robert Crandal on
Hello Dave!

You will be pleased to know that I HAVE discovered my own
solution to this annoying problem and here it is:

Only "load" your userform just ONCE and NEVER "unload" it!
If someone tries to close your form, rather than unloading the
form, just hide it instead. If someone tries to display your
form again, simply unhide it!

My point is, only "load" the form once, so that your form's
"initialize" function only gets called once. From that point,
simply write code that will hide or unhide the form itself,
but dont "unload" the form data structure from memory.

Let me know if you need code examples for this. I have
tested this thoroughly and I never see the RTE 75 error
any more!

As to what causes this problem, I am not entirely sure.
Are you using modeless forms when it crashes??

Robert



"Dave Unger" <dave.unger(a)sasktel.net> wrote in message
news:aabe2430-d8d2-4089-aea3-d830fc8e8e56(a)g18g2000vbr.googlegroups.com...
Hi Robert,

I started having similar problems quite recently (Run Time Error
75" ("Could Not Find The Specified Object"), seems to happen
sporadically when vba is trying to reference a form - doesn't seem to
limited to one particular form. I have a vague (very) notion that
there is an "orphaned" form object, caused by halting the code during
development. Also, whenever this happens, Excel will crash if I try
to save the application. This has been happening with increasing
frequency, and is quite frustrating. I'm running Winsows XP SP3 and
XL2007.

I'm just wondering if you've found the cause/solution to this yet.

regards,

Dave