form activate_event

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?
 
A

Albert D. Kallal

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?
 
A

Albert D. Kallal

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....
 
V

Vincent Verheul

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
 
V

Vincent Verheul

Note to my earlier posting:

'Call [Calling Form One].Redraw

should be:

'Call [Form_Calling Form One].Redraw
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Split form 0
How do I clear a form? 0
Displaying Data Forms in Excel 2016 for Mac 0
Hoe to Close a NoData Report 1
Error 438, Why? 4
Form won't activate 2
form focus confusion 1
cancel form unload 1

Top