how do i open another form
Printable View
how do i open another form
Form.Show
whatever the form name is,
form1 for instance
form1.show.
and say for instance u want to input something in the other form?
(open it first ^)
then do:
form1.label1.caption = "hello world!"
it wont work if the other form isn't open.
Not true. You can do it even when the form is unloaded and disabled.Quote:
Originally posted by Interesting
it wont work if the other form isn't open
Stiletto : Won't that still in turn load the form into memory? Setting a property on an object on another form does load the from, right?
No.
Lets say I have 2 forms, Form1 and Form2. The start up form is Form1.
If i do this:
It wont load Form2. And I can do it while Form2 is unloaded or disabledVB Code:
Form2.Label1.Caption = "Something"
ut doesn't it load it into memory?
I'm sure that you can do it even if the form is unloaded or disabled, and it wont load the form into memory.
This way allows you to set all control as you want and then load the form.
Yes. I load the form, set controls, the display. I never have just set a control on a form, kinda like I would use it in the future. I only set the controls on ther form that I would load up next....
Or am I missing something? :confused:
No, Stilleto, you're wrong about that. Any time you reference a form, it gets loaded. See your MSDN documentation.
Here's what I do to find out if a form is loaded without referencing specific forms. First, I give each form a unique tag. Then I check it like this:
VB Code:
If FormLoaded ("frmOptions", False) then ' do whatever end if Public Function FormLoaded(sTag As String, RestoreWindow As Boolean) As Boolean Dim frm As Form ' Loops through loaded forms and searches for a matching tag ' Restores window if RestoreWindow argument is true ' Form will not get loaded if it is not loaded already. On Error GoTo errHandler Hourglass True For Each frm In Forms If frm.Tag = sTag Then FormLoaded = True If RestoreWindow Then frm.WindowState = vbNormal frm.ZOrder 0 End If Exit For End If Next frm Hourglass False Exit Function errHandler: LogError Error, Err, vbNullString, "bForms.FormLoaded" Hourglass False End Function
You first sets all controls and then show/load the form.
VB Code:
sMsg = "Hello User, welcome back to your application" Form1.Label1.Caption = sMsg Form1.Show 'This will load form1 when Label1 is already set.
Quote:
Originally posted by Stiletto
No.
Lets say I have 2 forms, Form1 and Form2. The start up form is Form1.
If i do this:
It wont load Form2. And I can do it while Form2 is unloaded or disabledVB Code:
Form2.Label1.Caption = "Something"
in form1
VB Code:
Private Sub Command2_Click() Form2.Label1.Caption = "Test" End Sub
in form2
VB Code:
Private Sub Form_Load() MsgBox "Loading" End Sub
its loading :)
OMG...*Runs away* :D:)
K so it will load the form but you can do it even when the form is unloaded or disabled.
Peet is right, Stilleto. A lot of folks don't understand this and it screws them up down the road when they need things to happen in a certain order. Here's an example:
VB Code:
Sub Main () frmDatabase.Caption = "My awesome database app" frmDatabase.Filename = "c:\Program Files\AwesomeDB\db.mdb" frmDatabase.Show End Sub ' frmDatabase Sub Form_Load () ' Open the database here. You'll find the filename isn't set ' yet because the form_load event happened when you set ' the caption, but before you set the filename. End Sub