Connie,
It's all a matter of scope!
I'll bet you don't have Option Explicit enabled. From any code module,
select Tools --> Options. Then select the Editor tab, and tick the Require
Variable Declaration checkbox. In ALL your code modules, including forms and
reports, make sure the following appears at the top:
Option Compare Database
Option Explicit
Just for fun, select Compile from the Debug menu. Fix the error that's
reported, then click Compile again. Keep doing this, fixing each problem,
until no more problems are reported.
Now to your real problem. The issue is caused by the fact that frmX only
exists as long as the procedure in which it was declared, is running. As
soon as that procedure ends, the variable goes out of scope, and the
reference it holds to the form, is destroyed. When you destroy an object
reference, the object ceases to exist - thus your form disappears.
To get around this problem, declare the variable at module-level, like so:
Option Compare Database
Option Explicit
'Declare the object variable
Private FormX As Form_SwAvailabilityMainForm
You still have to set the reference in your procedure:
Private Sub OpenAnotherWindow_Click()
'Instantiate the object
Set frmX = New Form_SwAvailabilityMainForm
frmX.Visible = True 'Make it visible
frmX.SetFocus 'If you must
End Sub
Then when your procedure ends, the object variable remains alive. Just make
sure to kill the reference when you close the form.
Private Sub Form_Close()
Set FormX = Nothing 'Destroy the object reference
End Sub
Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
>I want to be able to open another instance of a form by pressing a button
>so
[quoted text clipped - 13 lines]
>
> Thanks in advance
Dirk Goldgar - 06 Apr 2005 15:00 GMT
> Connie,
>
[quoted text clipped - 37 lines]
> Set FormX = Nothing 'Destroy the object reference
> End Sub
Better change "FormX" to "frmX" where it appears in that code.

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
Graham R Seach - 08 Apr 2005 00:30 GMT
Oops. Thanks Dirk.
Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
>> Connie,
>>
[quoted text clipped - 39 lines]
>
> Better change "FormX" to "frmX" where it appears in that code.
Connie - 06 Apr 2005 19:55 GMT
thanks for all your help. its working now : )
> Connie,
>
[quoted text clipped - 60 lines]
> >
> > Thanks in advance