Calling a Sub from another Form

08-05-2004, 09:00 AM
I have a project with multiple forms. Most of them are displayed from the main form, Form1.


Form1 displays data from an access table. The other forms are used to add/edit data in the datatable. When the other forms are unloaded or closed, I need the datatable on form1 to be refreshed. This is done on Form1 with a sub "QuerySub()." Right now the QuerySub is put in a random control behind a picture box with the code:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub

So right now the Button is clicked from the other forms like so:


This works, but it isn't clean. Is there a way to execute a Sub on Form1 from Forms 2-5?

Thanks in Advance


08-05-2004, 10:36 AM
The more "oop correct" way to do it would be to make your QuerySub() public, pass a reference to form1 to your other forms whenever you instantiate them, and then call QuerySub() from from the other forms via the reference back to form1.

' In some other (sub) form:

Another approach would be to have a seperate object that models/represents your data and includes the update functionality and pass around references to the data object instead of having the data functionality tied into your form (which is a display/control element, not a data element, per se).


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum