Link to home
Start Free TrialLog in
Avatar of kinton
kinton

asked on

Add a sub form to a main form in visual basic

Hi,

Can some one explain to me how to add a subform to a main form in visual basic, then in turn link the forms together?

thanks
Avatar of cookre
cookre
Flag of United States of America image

Add a new form with Project/Add Form, say Form2.

In Form1, when you want to bring up Form2, do:
Form2.Show

If you don't want Form1 to appear while Form2 is up:
Form1.Hide
Form2.Show

When you're done with Form2, do
Form1.Show

And if you want the cursor to be in a particular field:
Form1.Fieldx.SetFocus
Avatar of Fox_What
Fox_What

Also, if you want form2 to show and not be able
to click on form1 while it is active you can do:

form2.show vbModal, form1.hwnd
Avatar of Mike McCracken
You asked about subforms in VB.  VB doesn't support a true subform.  You can simulate it as shown above.

mlmcc
It is so simple to do that.

Create a new form using File --> New Form --> give some name to that form( form2.frm)
then write the following code in button click event.

Private Sub Command1_click()
  form2.show
  form1.hide  ' Write this code if you want to hide the first window.
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Ivan_Skrinjaric
Ivan_Skrinjaric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kinton

ASKER

Sorry about the bad explanation of the question, but against all odds Ivan, you knew exactly what I needed.  Thanks for your help.