Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refreshing a "Recordset" on another form.

Status
Not open for further replies.

Duron

Technical User
Dec 13, 2004
15
DE
OK. I have 2 forms. The main form has an OLEDBConnection, 2 OLEDBDataAdapters, and 2 datasets.

There are 2 combo boxes on the form, both of which are bound to the same table of an Access file (hence the 2 of adapters and datasets), and are filled up with the primary key from that table on the form load.

There are textboxes for each combo box that change values when the combo box selection is changed. It will query against the selection in the combo box(primary key in the table) and put the values into the text boxes from the corresponding record.

So now I've made another form to enter in new records. And I would like those records to be displayed as soon as I go back the main form in the list in the combo box.

My ideal plan was to put this in a form close event of the add records form or something, but there is none. So I made a button on the add records form to "refresh" the data to be used on the main form.

I've tried saying that the datasets on the main form HaveChanges(), AcceptChanges(), datadapters.Fill(dataSets), mainForm.Refresh(), comboboxes.Refresh(). This is to no avail.

What would my best approach be to this?

If I was using VB 6, I would have made an ADO, and pre-bound all text boxes to the table, set the Recordsource for the ADO to a SQL statement to hit the first record in the db, then when the value in the combo box changed, change the record source in the ADO to a new SQL command, refresh it, and the new values would appear in the text box.

But how do I do it here?

Also, how do you unload a form in .Net? My ideal situation would be when I press the button on the main form to enter a new record, the main form goes away, and I press a button to re-load the main form on the add records form, and the add-records form goes away.

Thanks in advance.

 
Ahh but there is a form close event!
I just checked and this seems to work, hope it does what you need.

Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
MsgBox("formcloseing")
End Sub


If you want the IDE to create the event handler for you, you need to use the left drop down at the top of the code page and select "(Base Class Events)". Now on the right drop down you can select "closing".

HTH That'l do donkey, that'l do
[bravo]
 
Thanks for diggingthat up for me! Should work.
 
OK now, I've looked but can't find how to close the main form, not a newly dimmed main form, but the actual physical form that loads at startup. When I load form 2, I want form 1 to go away, and when Form 2 goes away, I make a new Form 1.
 
You need to load form1 from sub main rather than having it load as the main form. Otherwise you cannot close form1 without exiting the application. That'l do donkey, that'l do
[bravo]
 
Ohhhhh. OK that makes perfect sense. And then just Dim a Form1. Still takes some getting used to that a form is not a static thing anymore.
 
Hello, I am a newbie in VB.Net.
I have two forms,main form and form1. I made two global variables to hold their reference in a module. Then, I wrote a pubic method in main form. Afterwards, I open form1. How can I run the public method in main form when I am in form1?
 
Does form1 one have to open up in sub main? Unless you pass a reference to form1 it doesn't know that main form exists. If you open it from main form then you can access its parent property which will point to main form.

mmm yeah post back if you still have problems That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top