Click to See Complete Forum and Search --> : Help a Beginner


paki
May 14th, 2001, 05:57 PM
How do I load Forms?? I just started to learn VB today and I cant seem to figure out how to change to another form when I click a particular Command? Probably everyone in this forum knows how to do that...please let me know

coolbiz
May 14th, 2001, 06:05 PM
Example:

Form1: consists of Command1 (command button)

private Sub Command1_Click()
' load form2
Load Form2
Form2.Show
End Sub




Form2: consists of Command2

private Sub Command2_Click()
' close form
UnLoad Form2
End Sub




-Cool Bizs

VB Hack
May 15th, 2001, 12:30 AM
you can actually skip the load form2 and just use:
form2.show, the load will be automatic

Cimperiali
May 15th, 2001, 04:21 AM
...moreover (read others reply, first!) you can do a "strange" thing via VB:
you can declare a variable as form1 and then use the variable... ie:
have a form1 and form2 in your project.
in form1, at top declare:
dim frmF2 as Form
on command1 click, write:
set frmF2= new Form2
frmF2.show 'this will put a new istance of form2 each time you click on command1 in form1. Click 3 times and move form2 around and see...!

'do not forget this code in Form1 unload event:
Dim f As Form
For Each f In Forms
If f.Name <> "Form1" Then
Unload f 'unload loaded forms if any
Set f = Nothing
End If
Next f
If Not frmF2 Is Nothing Then
Set frmF2 = Nothing
End If
End Sub

'Amazing, isn't it?
:-)
Best regrads,
Cesare Imperiali

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.