Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Don't let the user open a new form 1

Status
Not open for further replies.

fterrazas

Technical User
Dec 29, 2000
43
0
0
ES
Hi, I have a program with menus and forms, a complete program, so what I want is when the user open a form1 in the program don't let him open another form, I mean if I have a Form1 loaded in the main form or window the user can't go to the menus or icons and start working with another form2, can I do this? I'm using Visual Basic 5.0 please help me, thanks.
 
Code:
Form1.Show vbModal

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Will this work for you?

If Form1.Visible Then
MsgBox ("Can't open 2 forms")
Else
form2.Show
End If

Regards,
Ryan
 
Both answers doesn't work, the first with vbModal trigger me the error "Can't use in secondary forms" something about MDI, and the second because I load the forms with a dropdown Menu, like a toolbar. Please Is another way to do it?
 
AndyWatt's answer may do for you, if the vbModal doesn't give you issues.

Although Motor11's post seems to be a "simple" fix, it will also fix the problem, possibly with a better outcome (if you make the form modal, when you go to open a new form using the command, it will close the form you didn't want closed, and open up a second form).
 
If I only have 2 subforms maybe Motor11's answer do it for me, but I have near 30 subforms so I ahve to put that code in every form? and the vbModal doesn't work it gives me an erros that vbModal MDI can't be used in a secondary form.
 
It seems to me that you're using a MDI application style, that is, a parent MDIForm and the childs forms. If you want the user to use only one form at a time in ALL your application, then, is better to create an application with no MDI forms in it. It coulb be done by pasting the code of your main form into a new one and making this your main form, and in the rest of the forms change the property MDIChild to false.

Hope this helps,

David.
 

You could use a public variable in a module...
[tt]
Option Explicit

Public LoadedChildName As String
[/tt]

Then in each form load/unload events...
[tt]
Private Sub Form_Load()
LoadedChildName = Me.Name
End Sub

Private Sub Form_QueryUnload()
LoadedChildName = vbNullString
End Sub
[/tt]

And then finally in your menu you could use...
[tt]
Dim F As Form
If LoadedChildName <> vbNullString Then
For Each F In Forms
If F.Name = LoadedChildName Then
Unload F
Exit For
End If
Next
End If
[/tt]

Before you load the next form that the user has selected.

Good Luck

 
Thnks to all for ur help, and specially to vb5prgrmr it works good I have to change some things but it's ok. Thnks
 
So give the (wo)man a star if his post was helpful/expert!

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
&quot;Why does my program keep showing error messages every time something goes wrong?&quot;
 
Or, since you said you are opening the form with a drop down menu, you could just disable ( on form load ) / enable ( on form unload ) the menu item that loads the form.

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top