The easiest way would be to use Access global variable, to read then in the
open event, and to write into them in the unload event of the form...
if that is not applicable (because you don't like global variables, or
because you cannot relay on 'fixed' variable names):
add public methods to the form, say Initialise and GetArgs:
---frm-----------------------
Public Sub Initialise(x As long, y As long)
' do something with x and y
' probably setting some control value
... = x
... = y
End Sub
Public Sub GetArgs( ByRef x As long, ByRef y As long)
x = ...
y = ...
End Sub
--------------------------------
So, programA creates the form object frm,
programA calls the method frm.Initialise
programA makes the form visible, frm.Visible=true
and before the form closes definitively
programA calls the method frm.GetArgs
The tricky part is probably that your code is under frm flow of execution,
NOT under programA flow of execution, when frm closes (ie, your programA is
NOT the one who closes frm, but it is the end user, trough the GUI, who
decided to close it). If so, in the Unload event of frm, you would have to
make programA calling frm.GetArgs method. If programA is a form, or another
object, you can pass it in the Initialise method of frm:
--- frm (revisited ) ------------------------------
Private programA_Is AS Object ' <-- new
Public Sub Initialise(x As long, y As long, _
who As object) ' < --modified
' do something with x and y
' probably setting some control value
... = x
... = y
programA_Is = who ' <--new
End Sub
Public Sub GetArgs( ByRef x As long, ByRef y As long)
x = ...
y = ...
End Sub
Private Sub Form_Unload(Cancel As Integer) ' <-- new
programA_Is.CallGetArgs( Me )
End Sub
------------------------------------------------
and programA method CallGetArgs is something that will supply the right
parameters to frm.CallArgs:
----programA ----------
Public Sub CallGetArg( x As Form_xyz )
x.CallArgs( foo, fee)
End Sub
-------------------------
(Note that instead of Object, you could use an Interface, to be safer, which
will impose that the third parameter of Initialise own a method
CallGetArgs( xxx As Form) and so the line
programAIs.CallGetArgs( Me )
would be validated at compile time, rather than at runtime.)
Well, there is nothing really wrong with global variables too, in general...
As far as error handling, mainly in Form_Unload, if any error occurs,
preferable to Cancel = true, at least in the debug version, so you may be in
a better position to track back the source of the error.
Vanderghast, Access MVP