Solved

vb stuff.... load form 2 from form 1

Posted on 2002-06-23
6
288 Views
Last Modified: 2010-05-02
I have a vb project which consists of 2 forms. And my startup object is form 1. In my form 1, I plan to create a command button to load form 2 and unload form 1 when I click on the button. Can anybody here provide me the source code in order to do this?
0
Comment
Question by:fl78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Accepted Solution

by:
dhammond-ku earned 20 total points
ID: 7101402
Hi there...Assuming that you call the button "Command1", here is source code that will load the new form and unload the original:

Private Sub Command1_Click()
Unload Form1
Load Form2
Form2.Show
End Sub

You could also simply hide the first form if you don't want to lose any data from it...To do so, simply add the line of code "Form1.Hide" instead of "Unload Form1". Then, to bring the form back up on the screen would be "Form1.Show"

Hope that helps,

Danny Hammond
hammond@ku.edu
0
 

Author Comment

by:fl78
ID: 7101409
Form 1:

Private Sub cmdCMR_Click()
    rs.Close
    Form1.Hide
    Load Form2
    Form2.Show
End Sub


Form 2:

Private Sub cmdGoToIMR1_Click()
    rs.Close
    Form2.Hide
    Load Form1
    Form1.Show
End Sub

when I click the button back and forth... there is run time error '3420

object invalid or no longer set... and the debug arrow point to rs.close..... Pls advice.
0
 
LVL 3

Expert Comment

by:ashunigam
ID: 7101588
declare rs in bas module.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:fl78
ID: 7101620
Form 1:

Private Sub cmdCMR_Click()
   rs.Close
   Unload Form1
   Load Form2
   Form2.Show
End Sub


Form 2:

Private Sub cmdGoToIMR1_Click()
   rs.Close
   Unload Form2
   Load Form1
   Form1.Show
End Sub

And if I use Unload instead of Hide.... there is no error. But, I might lose my data.....
0
 

Author Comment

by:fl78
ID: 7101622
ashunigam,

  Could you show me how to do this... as i am just a beginner .... thanks....
0
 
LVL 3

Expert Comment

by:ashunigam
ID: 7102190
select add Module. This will add a bas module to your project. Now public variables declared here could be accessed globally and will cease to exist when application is terminated. So you won't lose data as unloading will not clean the variable.
For this you don't need to do any other changes than moving the declared to a module.

Hope it helps.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month6 days, 2 hours left to enroll

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question