Execute after update on a passed control

G

Guest

I am using a calendar form for any dbl-clicked date on my access forms.
Dbl-click passes the Forms!formname.ctlname of the field clicked to my
calendar form.
On the calendar form, after the date is dbl-clicked it sets the passed
control name's .value to the date chosen. This works fine.
What I need to be able to do is check to see if that control has an
after-update event, and if so trigger it so that all validation is done.
Any ideas?

Thanks!
 
R

Rob Oldfield

Not sure if this is the best way of doing this... but if you do something
like consolidate all of your after update events into a single sub and pass
the control name to it....

public sub generic_after_update(ctlName as string)
select case ctlName
case control1
'control1 afterupdate
case control2
'control2 afterupdate
etc
etc
end select
end sub

....then, when you open the calendar form pass it the name of the control in
the openargs, and then call the after update routine with the openargs text
when you close the form. Note that the sub needs to be public so that you
call it via

call forms("formname").generic_after_update(me.openargs)
 
G

Guest

I appreciate the post, however this would be EXTREMELY cumbersome. My
validation is mostly private form based, andthe [Me.] form reference is
written in most all of them. By using a public function, i would have to
have ability to pass many different types of fields from every form in order
to validate...not easy to do at all! (unless I am missing something entirely)
I know it is easy to run a control-based event from anywhere in the database
(using forms!frmname.ctlname_AfterUpdate), so there should be a way to do
this I would think.

Thanks!
 
R

Rob Oldfield

You don't need to lose the me. references. Put the public sub in the form
and it will function in just the same way. And I don't believe there is a
way to run code specified by a string (as in call str+"_afterupdate"). You
could Google a recent thread "Executing a line of code defined in a string"
but I don't think there's a particularly clean way to do what you're after.

Though I've just thought of something which I'm going to go away and think
about....




GaryG said:
I appreciate the post, however this would be EXTREMELY cumbersome. My
validation is mostly private form based, andthe [Me.] form reference is
written in most all of them. By using a public function, i would have to
have ability to pass many different types of fields from every form in order
to validate...not easy to do at all! (unless I am missing something entirely)
I know it is easy to run a control-based event from anywhere in the database
(using forms!frmname.ctlname_AfterUpdate), so there should be a way to do
this I would think.

Thanks!

Rob Oldfield said:
Not sure if this is the best way of doing this... but if you do something
like consolidate all of your after update events into a single sub and pass
the control name to it....

public sub generic_after_update(ctlName as string)
select case ctlName
case control1
'control1 afterupdate
case control2
'control2 afterupdate
etc
etc
end select
end sub

....then, when you open the calendar form pass it the name of the control in
the openargs, and then call the after update routine with the openargs text
when you close the form. Note that the sub needs to be public so that you
call it via

call forms("formname").generic_after_update(me.openargs)
 
R

Rob Oldfield

Hmm. OK. Still messy but seems to work for me.

Presumably in your calendar form you have a variable (call it strCtl) that
contains the name of the calling control. If that's the case then this (on
the calendar form) triggers the after update event...

Forms!MainForm(strCtl).SetFocus
Forms!MainForm(strCtl).Text = cstr(YourDateVariable)


Rob Oldfield said:
You don't need to lose the me. references. Put the public sub in the form
and it will function in just the same way. And I don't believe there is a
way to run code specified by a string (as in call str+"_afterupdate"). You
could Google a recent thread "Executing a line of code defined in a string"
but I don't think there's a particularly clean way to do what you're after.

Though I've just thought of something which I'm going to go away and think
about....




GaryG said:
I appreciate the post, however this would be EXTREMELY cumbersome. My
validation is mostly private form based, andthe [Me.] form reference is
written in most all of them. By using a public function, i would have to
have ability to pass many different types of fields from every form in order
to validate...not easy to do at all! (unless I am missing something entirely)
I know it is easy to run a control-based event from anywhere in the database
(using forms!frmname.ctlname_AfterUpdate), so there should be a way to do
this I would think.

Thanks!

Rob Oldfield said:
Not sure if this is the best way of doing this... but if you do something
like consolidate all of your after update events into a single sub and pass
the control name to it....

public sub generic_after_update(ctlName as string)
select case ctlName
case control1
'control1 afterupdate
case control2
'control2 afterupdate
etc
etc
end select
end sub

....then, when you open the calendar form pass it the name of the control in
the openargs, and then call the after update routine with the openargs text
when you close the form. Note that the sub needs to be public so that you
call it via

call forms("formname").generic_after_update(me.openargs)


I am using a calendar form for any dbl-clicked date on my access forms.
Dbl-click passes the Forms!formname.ctlname of the field clicked to my
calendar form.
On the calendar form, after the date is dbl-clicked it sets the passed
control name's .value to the date chosen. This works fine.
What I need to be able to do is check to see if that control has an
after-update event, and if so trigger it so that all validation is done.
Any ideas?

Thanks!
 

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