[RESOLVED] How to load data in second Form ??
hi,
I have an application with 2 forms.
-Form 1 : searches the account in the database;
-Form 2: display account information (ex. account name, address etc) in Datagrids and Text boxes.
My idea is, once the customer is known on Form 1 , I need to automatically Load the corresponding data (ex. account name, address etc) in Form 2.
So far I have not been able to do it automatically, so I had to create a command button on Form2, to load the data.
Any ideas on how to do it? (without using the Load button on Form2)
Thanks,
Joao
Re: How to load data in second Form ??
When you load the account, doesn't that trigger an event?
Is form2 already loaded, or do you want it to automatically load up?
is it a MDI form?
Re: How to load data in second Form ??
hi,
I first search the account on the database based on the information typed on Form1. Don't know if the account search, generates an event . How can I find that out ?
Form2 is a standard SDI Form.
On Form2, i have some SqlCommands that need the customer id (from Form1) as input.
I'm not able to load Form2, by running the Sql statements . I tried instantiating the Form2 and call the Form_Load procedure, but it doesn't work either.
Joao.
Re: How to load data in second Form ??
Hi,
First of all, to access objects on other forms look in the codebank at
http://www.vbforums.com/showthread.php?t=313050
Second, the actual searching of the account in form1 IS initiated by an event. That event may be a Search button or may be the Load or Activated events of the form. If you want to progress to form2 immediately the account data has been collected, then (assuming that the search was generated by a button) put the code starting form2 at the end of the other code in that button. Something like:
VB Code:
Dim frm2 As New fclsForm2
frm2.ShowDialog()
Then in the Load event of fclsForm2 put your code to refer to the values in form1 and apply them to the database.
Hope that helps.
Re: How to load data in second Form ??
Thanks so much it worked just fine.
The only problem now, is when i do a Frm2.ShowDialog() , the Form1 is still opened in the background.
How can I close Form1 once Form2 is loaded ?
Tried Close() , but it does not work . Form1 is just closed when Form2 is closed also !
Re: How to load data in second Form ??
I had the same problem too...
I decided to go to the MDI forms route
it is alot easier and more organised...
Re: How to load data in second Form ??
Quote:
Originally Posted by jfortes
Thanks so much it worked just fine.
The only problem now, is when i do a Frm2.ShowDialog() , the Form1 is still opened in the background.
How can I close Form1 once Form2 is loaded ?
Tried Close() , but it does not work . Form1 is just closed when Form2 is closed also !
What do you want to do? Keep form1 open but invisible? If so amend the code to
VB Code:
Dim frm2 As New fclsForm2
Me.Hide
frm2.ShowDialog()
Me.Show
Re: [RESOLVED] How to load data in second Form ??
Thanks so much, i will implement this change.
I've set the status of this thread to "resolved".
João.