form activate_event

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

I have a sub that runs in the form_activate event. I did this to update
data after another data entry form was closed. The problem is when I
cancel the data entry form and the focus returns to the first form the
form_activate event runs the sub even though no data has changed. This is an
unnecessary action. I think I want to place some code in the close button
on the data entry form to run the sub in the first form.

What is the process to run a private sub that exists on another form?
 
Jeff said:
I have a sub that runs in the form_activate event. I did this to update
data after another data entry form was closed. The problem is when I
cancel the data entry form and the focus returns to the first form the
form_activate event runs the sub even though no data has changed. This is
an
unnecessary action. I think I want to place some code in the close button
on the data entry form to run the sub in the first form.

What is the process to run a private sub that exists on another form?
 
Why not just make the sub public in the form, and then you can simply call
it on the other forms close event...

Call forms!MyFirstForm.MySubName

Also, any function that you name as public function instantly becomes a
METHOD of the form. For, example, for special delete code in all my forms I
use:

forms!MyFormName.MyDelete

And, to refresh a form, but not loose the current record position, then I
use:

forms!MyFormName.MyRefresh

And, get out the property "LET", and that even lets you pass values to a
form:

forms!MyFormName.MyGoToID = 123

The code for the above could be:

Public Property LET MyGoToID(lngID as long)

dim strSql as string
strSql = "select * from customer where ID = " & lngID
me.RecordSouce = strSql

end Property

So, you can add functions, methods and even your own property's to a form,
and call them....
 
Hello Albert,

I have an additional question: can I make the "MyFormName" dynamic?

For instance, when I have a function in a module that is called by all of my
forms, and I want it to call a 'Redraw' function (Method) of the form that
called this function:

Function MyFunction()
Dim Frm as Form
Set Frm = Screen.ActiveForm
Debug.Print Frm.Name ' For example [Calling Form One]
'Call [Calling Form One].Redraw ' A public function of that form <static
syntax>
Call [Frm.Name].Redraw ' This doesn't work <dynamic syntax>
End Function

TIA
Vincent
 
Note to my earlier posting:

'Call [Calling Form One].Redraw

should be:

'Call [Form_Calling Form One].Redraw
 
Back
Top