By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

Trap form closing

P: n/a
Hi All

I have a project that has 2 forms, the main form displays various sql
data items and the second form is for editing / updating 1 particular
table.

I would like to refresh a dataset on from 1 when form 2 closes. How
would I trap that event?

All ideas welcome

Gavin

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Gavin schrieb:
Hi All

I have a project that has 2 forms, the main form displays various sql
data items and the second form is for editing / updating 1 particular
table.

I would like to refresh a dataset on from 1 when form 2 closes. How
would I trap that event?

All ideas welcome


Depends. Are the Forms shown modeless or modally? Do both always exist?
Where are they created?

In general, you can use the Addhandler statement to attach to an event
handler, but where and how to get the reference to the other Form depends on
the answers to the questions above.

Armin
Nov 21 '05 #2

P: n/a
In form2, handle the Closing event. In that event handler, call a public
method in form1 that does whatever you want.

"Gavin" wrote:
Hi All

I have a project that has 2 forms, the main form displays various sql
data items and the second form is for editing / updating 1 particular
table.

I would like to refresh a dataset on from 1 when form 2 closes. How
would I trap that event?

All ideas welcome

Gavin

Nov 21 '05 #3

P: n/a
"Gavin" <ga********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I would like to refresh a dataset on from 1 when form 2 closes.
How would I trap that event?


The Form's Closing Event is the one you're after, but it's only part
of the problem.

In Form 1, expose a Public method that will cause the DataSet to be
refreshed, as in :

Class Form1
. . .
Public Sub RefreshDataSet()
' Refresh DataSet
End Sub

When you instantiate Form2 (from Form 1, presumably) pass a
reference to the original Form. Many ways to do this, but a Public
property might be easiest, as in

Class Form2
. . .
Public WriteOnly Property CallingForm() As Form1
Set( Value as Form1 )
m_oCaller = Value
End Set
End Property
. . .
Private m_oCaller as Form1 = Nothing

then, back in Form1

Sub SomewhereInForm1()
Dim f as New Form2

f.CallingForm = Me
f.Show()
End Sub

In Form 2, handle the Closing Event and call the above method,
as in

Class Form2
. . .
Private Sub Form_Closing( _
ByVal sender as Object _
, ByVal e as System.ComponentModel.CancelEventArgs _
) Handles Form2.Closing

m_oCaller.RefreshDataSet()

End Sub

HTH,
Phill W.
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.