Kick Starting AfterUpdate Event in another Form

P

Pete Halfacree

I am using the ActiveX Calendar to Input Dates to another
form and need to kick start the Control's AfterUpdate
Event. My current workround is using SendKeys which is
messy and unpredictable.

Does anyone have a better solution?

The Initial Forms address is passed to the Calendar Form
OpenArgs as: DoCmd.OpenForm "frmCalendar", , , , , ,
Me.Name.

After Date selection the following procedure is invoked:

Private Sub UpdateFormControl()
'If Calendar is opened from another form then
' update the active control in that form
If Not IsNull(Me.OpenArgs) Then
Me.Visible = False
For Each frm In Forms
If frm.Name = Me.OpenArgs Then
With frm
frm.Visible = True
frm.ActiveControl =
Me.ActiveControl.Object
'The next bit triggers the OnFocus Event for the Active
Control
'by simulating operator input Enter & Back Tab
'The OnFocus Event will then trigger the AfterUpdate event
if the Data has changed
.SetFocus
SendKeys "~"
SendKeys "+{TAB}"
End With
End If
Next frm
End If
DoCmd.Close acForm, "frmCalendar", acSaveNo
 
T

TC

If a control has an event (including but not limited to AfterUpdate) - say:

private sub ctl_AfterUpdate()

you can invoke that event procedure manually, just like any other procedure:

msgbox "calling.."
ctl_AfterUpdate
msgbox "called!"

From a code structure viewpoint, it may be better to put the common code in
a seperate procedure:

private sub ctl_AfterUpdate()
do_stuff
end stuff

msgbox "calling.."
do_stuff
msgbox "called!"

private do_stuff()
...
end sub

Now, if you need to add something extra for the AfterUpdate case, but not
for the "called programatically" case, you can do that easily.

HTH,
TC
 
P

Pete Halfacree

TC, Thank you for your prompt response.

Calling the Sub your way can only be done within the form
having the Event Procedure and this how I have called up
the Event (based on the GotFocus Event of the Control
stimulated by the Enter + Back Tab).

I have tried to Run the procedure from the Calendar form
using:
Run frm.ActiveControl.Name & "_AfterUpdate [Event
Procedure]".
Access tells me it can't find the procedure.

I have also tried Run frm.name & "." &
frm.ActiveControl.Name & "_AfterUpdate" and still no joy.

Surely there must be a way!

Regards, Pete
 
T

TC

Pete, if you want to call a procedure or function within a form module from
"outside", you must declare the procedure or function Public:

form #1's module:

PUBLIC sub do_stuff
msgbox "in do_stuff!"
end sub

then from some other form:

forms("... the form name ...").do_stuff

But generally it is not good practice to do that. If two forms call the same
procedure, it is best to declare that procedure in a module on the Modules
table. Declare it Public, as above. Then either form (or any other sub or
function in any module) can call it just by saying: do_stuff.

If it needs to know values from the calling form, just pass those values as
parameters:

declaration of do_stuff in a Module:

Public do_stuff (Blah as Integer)
msgbox "do_stuff! " & Blah
end

calling do_stuff from within a form module, passing the integer value from
control txtBlah:

do_stuff me![txtBlah]

HTH,
TC


Pete Halfacree said:
TC, Thank you for your prompt response.

Calling the Sub your way can only be done within the form
having the Event Procedure and this how I have called up
the Event (based on the GotFocus Event of the Control
stimulated by the Enter + Back Tab).

I have tried to Run the procedure from the Calendar form
using:
Run frm.ActiveControl.Name & "_AfterUpdate [Event
Procedure]".
Access tells me it can't find the procedure.

I have also tried Run frm.name & "." &
frm.ActiveControl.Name & "_AfterUpdate" and still no joy.

Surely there must be a way!

Regards, Pete
-----Original Message-----
If a control has an event (including but not limited to AfterUpdate) - say:

private sub ctl_AfterUpdate()

you can invoke that event procedure manually, just like any other procedure:

msgbox "calling.."
ctl_AfterUpdate
msgbox "called!"

From a code structure viewpoint, it may be better to put the common code in
a seperate procedure:

private sub ctl_AfterUpdate()
do_stuff
end stuff

msgbox "calling.."
do_stuff
msgbox "called!"

private do_stuff()
...
end sub

Now, if you need to add something extra for the AfterUpdate case, but not
for the "called programatically" case, you can do that easily.

HTH,
TC
 
P

Pete Halfacree

TC,

This is the response I was looking for.

I will take your comments "On Board" about using Public
Modules, although I will have to analyse my Process again.

Thank you once more.

Regards,

Pete
-----Original Message-----
Pete, if you want to call a procedure or function within a form module from
"outside", you must declare the procedure or function Public:

form #1's module:

PUBLIC sub do_stuff
msgbox "in do_stuff!"
end sub

then from some other form:

forms("... the form name ...").do_stuff

But generally it is not good practice to do that. If two forms call the same
procedure, it is best to declare that procedure in a module on the Modules
table. Declare it Public, as above. Then either form (or any other sub or
function in any module) can call it just by saying: do_stuff.

If it needs to know values from the calling form, just pass those values as
parameters:

declaration of do_stuff in a Module:

Public do_stuff (Blah as Integer)
msgbox "do_stuff! " & Blah
end

calling do_stuff from within a form module, passing the integer value from
control txtBlah:

do_stuff me![txtBlah]

HTH,
TC


TC, Thank you for your prompt response.

Calling the Sub your way can only be done within the form
having the Event Procedure and this how I have called up
the Event (based on the GotFocus Event of the Control
stimulated by the Enter + Back Tab).

I have tried to Run the procedure from the Calendar form
using:
Run frm.ActiveControl.Name & "_AfterUpdate [Event
Procedure]".
Access tells me it can't find the procedure.

I have also tried Run frm.name & "." &
frm.ActiveControl.Name & "_AfterUpdate" and still no joy.

Surely there must be a way!

Regards, Pete
-----Original Message-----
If a control has an event (including but not limited to AfterUpdate) - say:

private sub ctl_AfterUpdate()

you can invoke that event procedure manually, just like any other procedure:

msgbox "calling.."
ctl_AfterUpdate
msgbox "called!"

From a code structure viewpoint, it may be better to
put
the common code in
a seperate procedure:

private sub ctl_AfterUpdate()
do_stuff
end stuff

msgbox "calling.."
do_stuff
msgbox "called!"

private do_stuff()
...
end sub

Now, if you need to add something extra for the AfterUpdate case, but not
for the "called programatically" case, you can do that easily.

HTH,
TC


.
 
T

TC

Pete Halfacree said:
TC,

This is the response I was looking for.

I will take your comments "On Board" about using Public
Modules, although I will have to analyse my Process again.

Hi Pete. Note that I meant "the procedure or function", not "the module",
when I used the word "it" in the second sentence: "If two forms call the
same procedure, it is best to declare that procedure in a module on the
Modules tab. Declare >it< Public ..." That is, declare the procedure or
function Public, not the module. It is not a "public module". It is properly
called a "standard" module (as opposed to a "class" module).

Thank you once more.

No probs, good luck.

TC

Regards,

Pete
-----Original Message-----
Pete, if you want to call a procedure or function within a form module from
"outside", you must declare the procedure or function Public:

form #1's module:

PUBLIC sub do_stuff
msgbox "in do_stuff!"
end sub

then from some other form:

forms("... the form name ...").do_stuff

But generally it is not good practice to do that. If two forms call the same
procedure, it is best to declare that procedure in a module on the Modules
table. Declare it Public, as above. Then either form (or any other sub or
function in any module) can call it just by saying: do_stuff.

If it needs to know values from the calling form, just pass those values as
parameters:

declaration of do_stuff in a Module:

Public do_stuff (Blah as Integer)
msgbox "do_stuff! " & Blah
end

calling do_stuff from within a form module, passing the integer value from
control txtBlah:

do_stuff me![txtBlah]

HTH,
TC


TC, Thank you for your prompt response.

Calling the Sub your way can only be done within the form
having the Event Procedure and this how I have called up
the Event (based on the GotFocus Event of the Control
stimulated by the Enter + Back Tab).

I have tried to Run the procedure from the Calendar form
using:
Run frm.ActiveControl.Name & "_AfterUpdate [Event
Procedure]".
Access tells me it can't find the procedure.

I have also tried Run frm.name & "." &
frm.ActiveControl.Name & "_AfterUpdate" and still no joy.

Surely there must be a way!

Regards, Pete
-----Original Message-----
If a control has an event (including but not limited to
AfterUpdate) - say:

private sub ctl_AfterUpdate()

you can invoke that event procedure manually, just like
any other procedure:

msgbox "calling.."
ctl_AfterUpdate
msgbox "called!"

From a code structure viewpoint, it may be better to put
the common code in
a seperate procedure:

private sub ctl_AfterUpdate()
do_stuff
end stuff

msgbox "calling.."
do_stuff
msgbox "called!"

private do_stuff()
...
end sub

Now, if you need to add something extra for the
AfterUpdate case, but not
for the "called programatically" case, you can do that
easily.

HTH,
TC


.
 

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

Top