Anything similar to Handlers in Access / VB 2003? (All controls call same function)

R

Rico

Hello,

I have a form that has 120 text box controls that all have to call the same
function during their BeforeUpdate event. I know in VB.net you can use
handles to attach the control name to the function without having to define
it in the control event.

Is there an easy way to make the controls all use the same function on
BeforeUpdate without having to call the function from each BeforeUpdate
event?

Any ideas would be greatly appreciated.

Thanks!
Rick
 
D

Douglas J. Steele

As long as the function doesn't require any custom arguments, you can select
all the controls, then put =FunctionName() for the BeforeUpdate property. If
you need to pass the control name, you're out of luck: you'll have to change
the function to use the Screen.ActiveControl to get a reference to the
control.
 
J

John W. Vinson

As long as the function doesn't require any custom arguments, you can select
all the controls, then put =FunctionName() for the BeforeUpdate property. If
you need to pass the control name, you're out of luck: you'll have to change
the function to use the Screen.ActiveControl to get a reference to the
control.

It requires editing each control separately, but you can in fact pass the name
of the control:

=FunctionName(Form.controlname)

It wouldn't be too hard to write some VBA to assign this value to the event
for each control.

John W. Vinson [MVP]
 
D

Douglas J. Steele

John W. Vinson said:
It requires editing each control separately, but you can in fact pass the
name
of the control:

=FunctionName(Form.controlname)

It wouldn't be too hard to write some VBA to assign this value to the
event
for each control.

True. Where you would still run into problems, though, is if you wanted to
use variables associated with the default event, such as wanting to use the
Cancel parameter in the BeforeUpdate or BeforeInsert events. Or have I
missed a possible work-around?
 
J

John W. Vinson

True. Where you would still run into problems, though, is if you wanted to
use variables associated with the default event, such as wanting to use the
Cancel parameter in the BeforeUpdate or BeforeInsert events. Or have I
missed a possible work-around?

I'm not aware of any way to do this, no.

John W. Vinson [MVP]
 
R

Rico

Thanks guys,

Yea, I have to use the Cancel, so looks like I'm coding...one control at a
time. ;)
 
D

Douglas J. Steele

As we alluded to, it's possible to write code to create the event procedures
for you.

Take a look at the CreateEventProc and InsertLine methods of the Module
object.
 
G

Guest

Yea, I have to use the Cancel, so looks like I'm coding...one control at
a

Perhaps you want a custom Validation function instead of a Before Update
function.
=IsValid([form].activectrl)

You don't actually have to validate in your validation function: you can
add what ever side effect you want. There is no constraint on the signature
of the validation function: you can use whatever parameters you want.

(david)
 
G

Guest

sorry: .ACTIVECONTROL
(david)

Douglas J. Steele said:
As we alluded to, it's possible to write code to create the event procedures
for you.

Take a look at the CreateEventProc and InsertLine methods of the Module
object.
 
D

Douglas J. Steele

I don't see why you'd even need to pass [form].ActiveControl. to the
validation function: you can simply refer to it in the function.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


a

Perhaps you want a custom Validation function instead of a Before Update
function.
=IsValid([form].activectrl)

You don't actually have to validate in your validation function: you can
add what ever side effect you want. There is no constraint on the
signature
of the validation function: you can use whatever parameters you want.

(david)

Douglas J. Steele said:
As we alluded to, it's possible to write code to create the event procedures
for you.

Take a look at the CreateEventProc and InsertLine methods of the Module
object.
 
G

Guest

2 reasons

1) I wanted an example with passing a parameter

2) I use that form in some of my event functions because
it generalises the function so that it can also be used to act
on controls which are not the active control.

(david)

Douglas J. Steele said:
I don't see why you'd even need to pass [form].ActiveControl. to the
validation function: you can simply refer to it in the function.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Yea, I have to use the Cancel, so looks like I'm coding...one control
at
a

Perhaps you want a custom Validation function instead of a Before Update
function.
=IsValid([form].activectrl)

You don't actually have to validate in your validation function: you can
add what ever side effect you want. There is no constraint on the
signature
of the validation function: you can use whatever parameters you want.

(david)

Douglas J. Steele said:
As we alluded to, it's possible to write code to create the event procedures
for you.

Take a look at the CreateEventProc and InsertLine methods of the Module
object.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks guys,

Yea, I have to use the Cancel, so looks like I'm coding...one control
at a
time. ;)

message
On Wed, 10 Oct 2007 17:48:50 -0400, "Douglas J. Steele"

As long as the function doesn't require any custom arguments, you can
select
all the controls, then put =FunctionName() for the BeforeUpdate
property. If
you need to pass the control name, you're out of luck: you'll have to
change
the function to use the Screen.ActiveControl to get a reference to
the
control.

It requires editing each control separately, but you can in fact pass
the name
of the control:

=FunctionName(Form.controlname)

It wouldn't be too hard to write some VBA to assign this value to the
event
for each control.

True. Where you would still run into problems, though, is if you
wanted
to use variables associated with the default event, such as wanting to
use the Cancel parameter in the BeforeUpdate or BeforeInsert events.
Or
have I missed a possible work-around?
 

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