Code for all controls on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a control on my form that locks a particular record when it is
populated with a date. When that record is locked and a user clicks in a
field I want a message box to appear telling them that the record is locked
and cannot be edited. I created a function with my msgbox so that I can have
all my controls point to but since I have close to 50 controls is there an
easier way to have all the fields point to this function instead of putting
code in each of the "On Click" events of all my controls?
 
Hi Tina,
I read that thread but I'm not sure I understand how to set that up. I
already have the msgbox function in my forms module. I just don't know how to
tie it into all the "On Click" events of all my controls so that it appears
when the record is locked due to a date in one of my controls.
 
Make sure that your existing module is a function, not a sub. (It doesn't
matter whether or not the function returns any value. In fact, even if it
does, the value that's returned isn't going to be usable in what follows).

Select all of the controls on the form for which you want the function above
to apply. (Remember: not all controls have an OnClick event...) You do this
selection by "lassoing" the relevant controls using your mouse, or by
holding down the Shift key while you click on the controls one-by-one, or a
combination of the two.

Once you've selected all of the controls of interest, look at the Properties
window. It's only going to display properties that exist for all of the
selected controls. If you did your selection properly (i.e.: if you didn't
accidentally select a control that doesn't have an OnClick event), you
should see the OnClick event in the Properties window. Simply type
=MyFunctionName() in the property box beside that event name, and it will
apply to all of the selected controls. (In other words, it will put it in
the OnClick event of all 50 controls at once)
 
Thanks Doug, that worked perfectly!

Douglas J. Steele said:
Make sure that your existing module is a function, not a sub. (It doesn't
matter whether or not the function returns any value. In fact, even if it
does, the value that's returned isn't going to be usable in what follows).

Select all of the controls on the form for which you want the function above
to apply. (Remember: not all controls have an OnClick event...) You do this
selection by "lassoing" the relevant controls using your mouse, or by
holding down the Shift key while you click on the controls one-by-one, or a
combination of the two.

Once you've selected all of the controls of interest, look at the Properties
window. It's only going to display properties that exist for all of the
selected controls. If you did your selection properly (i.e.: if you didn't
accidentally select a control that doesn't have an OnClick event), you
should see the OnClick event in the Properties window. Simply type
=MyFunctionName() in the property box beside that event name, and it will
apply to all of the selected controls. (In other words, it will put it in
the OnClick event of all 50 controls at once)
 
Actually I do have one follow up question. I put the function name in all the
"OnClick" events for all my controls but it doesn't seem to work for combo
boxes. Should I be doing something different for those?
 
Also, what are you clicking on in the combo box: the box itself, or the
arrow to the right?
 
I tried clicking on the arrow and the box iteself. So both ways it doesn't
seem to work.
Here is the code in my function

Private Function CheckClosedRecord()

If IsNull([CEODate]) Then

Else
MsgBox "This record is closed. Please contact the Database
Administrator or Quality Manager if you need to edit this record"
End If

End Function
 
Do you know that the code is being called? Put a breakpoint into it, or a
message box outside of the If statement, just to be sure.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
I tried clicking on the arrow and the box iteself. So both ways it doesn't
seem to work.
Here is the code in my function

Private Function CheckClosedRecord()

If IsNull([CEODate]) Then

Else
MsgBox "This record is closed. Please contact the Database
Administrator or Quality Manager if you need to edit this record"
End If

End Function

Douglas J. Steele said:
Also, what are you clicking on in the combo box: the box itself, or the
arrow to the right?
 
The code is being called because it works for all my text boxes.

Douglas J. Steele said:
Do you know that the code is being called? Put a breakpoint into it, or a
message box outside of the If statement, just to be sure.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
I tried clicking on the arrow and the box iteself. So both ways it doesn't
seem to work.
Here is the code in my function

Private Function CheckClosedRecord()

If IsNull([CEODate]) Then

Else
MsgBox "This record is closed. Please contact the Database
Administrator or Quality Manager if you need to edit this record"
End If

End Function

Douglas J. Steele said:
Also, what are you clicking on in the combo box: the box itself, or the
arrow to the right?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


What's the code in the function?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message Actually I do have one follow up question. I put the function name in
all
the
"OnClick" events for all my controls but it doesn't seem to work for
combo
boxes. Should I be doing something different for those?

:

Make sure that your existing module is a function, not a sub. (It
doesn't
matter whether or not the function returns any value. In fact, even
if
it
does, the value that's returned isn't going to be usable in what
follows).

Select all of the controls on the form for which you want the
function
above
to apply. (Remember: not all controls have an OnClick event...) You
do
this
selection by "lassoing" the relevant controls using your mouse, or by
holding down the Shift key while you click on the controls
one-by-one,
or a
combination of the two.

Once you've selected all of the controls of interest, look at the
Properties
window. It's only going to display properties that exist for all of
the
selected controls. If you did your selection properly (i.e.: if you
didn't
accidentally select a control that doesn't have an OnClick event),
you
should see the OnClick event in the Properties window. Simply type
=MyFunctionName() in the property box beside that event name, and it
will
apply to all of the selected controls. (In other words, it will put
it
in
the OnClick event of all 50 controls at once)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message Hi Tina,
I read that thread but I'm not sure I understand how to set that
up. I
already have the msgbox function in my forms module. I just don't
know
how
to
tie it into all the "On Click" events of all my controls so that it
appears
when the record is locked due to a date in one of my controls.

:

the thread at
http://groups.google.com/group/micr...ss*+author:tina&rnum=1&hl=en#69089e7d34b618a3
explains how to set up a function call from the same event of
multiple
controls in a form, all at once. note that if you're only using
the
"msgbox
function" in one form, you can keep the function in that form's
module -
you
don't have to add it to a standard module (that part of the
thread's
instructions was specific to the situation at hand).

hth


in
message I have a control on my form that locks a particular record when
it
is
populated with a date. When that record is locked and a user
clicks
in
a
field I want a message box to appear telling them that the
record
is
locked
and cannot be edited. I created a function with my msgbox so
that I
can
have
all my controls point to but since I have close to 50 controls
is
there
an
easier way to have all the fields point to this function instead
of
putting
code in each of the "On Click" events of all my controls?
 
So it works for your text boxes. Is it being called for the combo box?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
The code is being called because it works for all my text boxes.

Douglas J. Steele said:
Do you know that the code is being called? Put a breakpoint into it, or a
message box outside of the If statement, just to be sure.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
I tried clicking on the arrow and the box iteself. So both ways it
doesn't
seem to work.
Here is the code in my function

Private Function CheckClosedRecord()

If IsNull([CEODate]) Then

Else
MsgBox "This record is closed. Please contact the Database
Administrator or Quality Manager if you need to edit this record"
End If

End Function

:

Also, what are you clicking on in the combo box: the box itself, or
the
arrow to the right?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message
What's the code in the function?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


in
message Actually I do have one follow up question. I put the function name
in
all
the
"OnClick" events for all my controls but it doesn't seem to work
for
combo
boxes. Should I be doing something different for those?

:

Make sure that your existing module is a function, not a sub. (It
doesn't
matter whether or not the function returns any value. In fact,
even
if
it
does, the value that's returned isn't going to be usable in what
follows).

Select all of the controls on the form for which you want the
function
above
to apply. (Remember: not all controls have an OnClick event...)
You
do
this
selection by "lassoing" the relevant controls using your mouse, or
by
holding down the Shift key while you click on the controls
one-by-one,
or a
combination of the two.

Once you've selected all of the controls of interest, look at the
Properties
window. It's only going to display properties that exist for all
of
the
selected controls. If you did your selection properly (i.e.: if
you
didn't
accidentally select a control that doesn't have an OnClick event),
you
should see the OnClick event in the Properties window. Simply type
=MyFunctionName() in the property box beside that event name, and
it
will
apply to all of the selected controls. (In other words, it will
put
it
in
the OnClick event of all 50 controls at once)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


in
message Hi Tina,
I read that thread but I'm not sure I understand how to set that
up. I
already have the msgbox function in my forms module. I just
don't
know
how
to
tie it into all the "On Click" events of all my controls so that
it
appears
when the record is locked due to a date in one of my controls.

:

the thread at
http://groups.google.com/group/micr...ss*+author:tina&rnum=1&hl=en#69089e7d34b618a3
explains how to set up a function call from the same event of
multiple
controls in a form, all at once. note that if you're only using
the
"msgbox
function" in one form, you can keep the function in that form's
module -
you
don't have to add it to a standard module (that part of the
thread's
instructions was specific to the situation at hand).

hth


"Secret Squirrel" <[email protected]>
wrote
in
message
I have a control on my form that locks a particular record
when
it
is
populated with a date. When that record is locked and a user
clicks
in
a
field I want a message box to appear telling them that the
record
is
locked
and cannot be edited. I created a function with my msgbox so
that I
can
have
all my controls point to but since I have close to 50
controls
is
there
an
easier way to have all the fields point to this function
instead
of
putting
code in each of the "On Click" events of all my controls?
 
Nope, it's not being called for the combo boxes.

Douglas J. Steele said:
So it works for your text boxes. Is it being called for the combo box?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
The code is being called because it works for all my text boxes.

Douglas J. Steele said:
Do you know that the code is being called? Put a breakpoint into it, or a
message box outside of the If statement, just to be sure.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message I tried clicking on the arrow and the box iteself. So both ways it
doesn't
seem to work.
Here is the code in my function

Private Function CheckClosedRecord()

If IsNull([CEODate]) Then

Else
MsgBox "This record is closed. Please contact the Database
Administrator or Quality Manager if you need to edit this record"
End If

End Function

:

Also, what are you clicking on in the combo box: the box itself, or
the
arrow to the right?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message
What's the code in the function?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


in
message Actually I do have one follow up question. I put the function name
in
all
the
"OnClick" events for all my controls but it doesn't seem to work
for
combo
boxes. Should I be doing something different for those?

:

Make sure that your existing module is a function, not a sub. (It
doesn't
matter whether or not the function returns any value. In fact,
even
if
it
does, the value that's returned isn't going to be usable in what
follows).

Select all of the controls on the form for which you want the
function
above
to apply. (Remember: not all controls have an OnClick event...)
You
do
this
selection by "lassoing" the relevant controls using your mouse, or
by
holding down the Shift key while you click on the controls
one-by-one,
or a
combination of the two.

Once you've selected all of the controls of interest, look at the
Properties
window. It's only going to display properties that exist for all
of
the
selected controls. If you did your selection properly (i.e.: if
you
didn't
accidentally select a control that doesn't have an OnClick event),
you
should see the OnClick event in the Properties window. Simply type
=MyFunctionName() in the property box beside that event name, and
it
will
apply to all of the selected controls. (In other words, it will
put
it
in
the OnClick event of all 50 controls at once)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


in
message Hi Tina,
I read that thread but I'm not sure I understand how to set that
up. I
already have the msgbox function in my forms module. I just
don't
know
how
to
tie it into all the "On Click" events of all my controls so that
it
appears
when the record is locked due to a date in one of my controls.

:

the thread at
http://groups.google.com/group/micr...ss*+author:tina&rnum=1&hl=en#69089e7d34b618a3
explains how to set up a function call from the same event of
multiple
controls in a form, all at once. note that if you're only using
the
"msgbox
function" in one form, you can keep the function in that form's
module -
you
don't have to add it to a standard module (that part of the
thread's
instructions was specific to the situation at hand).

hth


"Secret Squirrel" <[email protected]>
wrote
in
message
I have a control on my form that locks a particular record
when
it
is
populated with a date. When that record is locked and a user
clicks
in
a
field I want a message box to appear telling them that the
record
is
locked
and cannot be edited. I created a function with my msgbox so
that I
can
have
all my controls point to but since I have close to 50
controls
is
there
an
easier way to have all the fields point to this function
instead
of
putting
code in each of the "On Click" events of all my controls?
 
The Click event for a combo box occurs when you click on something in the
list, not when you click on the box. If you want it to fire when the combo
box is selected, try the GotFocus event.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
Nope, it's not being called for the combo boxes.

Douglas J. Steele said:
So it works for your text boxes. Is it being called for the combo box?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
The code is being called because it works for all my text boxes.

:

Do you know that the code is being called? Put a breakpoint into it,
or a
message box outside of the If statement, just to be sure.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message I tried clicking on the arrow and the box iteself. So both ways it
doesn't
seem to work.
Here is the code in my function

Private Function CheckClosedRecord()

If IsNull([CEODate]) Then

Else
MsgBox "This record is closed. Please contact the Database
Administrator or Quality Manager if you need to edit this record"
End If

End Function

:

Also, what are you clicking on in the combo box: the box itself, or
the
arrow to the right?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message
What's the code in the function?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


"Secret Squirrel" <[email protected]>
wrote
in
message
Actually I do have one follow up question. I put the function
name
in
all
the
"OnClick" events for all my controls but it doesn't seem to work
for
combo
boxes. Should I be doing something different for those?

:

Make sure that your existing module is a function, not a sub.
(It
doesn't
matter whether or not the function returns any value. In fact,
even
if
it
does, the value that's returned isn't going to be usable in
what
follows).

Select all of the controls on the form for which you want the
function
above
to apply. (Remember: not all controls have an OnClick event...)
You
do
this
selection by "lassoing" the relevant controls using your mouse,
or
by
holding down the Shift key while you click on the controls
one-by-one,
or a
combination of the two.

Once you've selected all of the controls of interest, look at
the
Properties
window. It's only going to display properties that exist for
all
of
the
selected controls. If you did your selection properly (i.e.: if
you
didn't
accidentally select a control that doesn't have an OnClick
event),
you
should see the OnClick event in the Properties window. Simply
type
=MyFunctionName() in the property box beside that event name,
and
it
will
apply to all of the selected controls. (In other words, it will
put
it
in
the OnClick event of all 50 controls at once)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


"Secret Squirrel" <[email protected]>
wrote
in
message
Hi Tina,
I read that thread but I'm not sure I understand how to set
that
up. I
already have the msgbox function in my forms module. I just
don't
know
how
to
tie it into all the "On Click" events of all my controls so
that
it
appears
when the record is locked due to a date in one of my
controls.

:

the thread at
http://groups.google.com/group/micr...ss*+author:tina&rnum=1&hl=en#69089e7d34b618a3
explains how to set up a function call from the same event
of
multiple
controls in a form, all at once. note that if you're only
using
the
"msgbox
function" in one form, you can keep the function in that
form's
module -
you
don't have to add it to a standard module (that part of the
thread's
instructions was specific to the situation at hand).

hth


"Secret Squirrel" <[email protected]>
wrote
in
message
I have a control on my form that locks a particular record
when
it
is
populated with a date. When that record is locked and a
user
clicks
in
a
field I want a message box to appear telling them that the
record
is
locked
and cannot be edited. I created a function with my msgbox
so
that I
can
have
all my controls point to but since I have close to 50
controls
is
there
an
easier way to have all the fields point to this function
instead
of
putting
code in each of the "On Click" events of all my controls?
 
That worked perfectly in the GotFocus event. But when I did try it using the
OnClick event and selecting something from the pull down menu it still didn't
work. I guess it really doesn't matter at this point.

Douglas J. Steele said:
The Click event for a combo box occurs when you click on something in the
list, not when you click on the box. If you want it to fire when the combo
box is selected, try the GotFocus event.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
Nope, it's not being called for the combo boxes.

Douglas J. Steele said:
So it works for your text boxes. Is it being called for the combo box?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message The code is being called because it works for all my text boxes.

:

Do you know that the code is being called? Put a breakpoint into it,
or a
message box outside of the If statement, just to be sure.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message I tried clicking on the arrow and the box iteself. So both ways it
doesn't
seem to work.
Here is the code in my function

Private Function CheckClosedRecord()

If IsNull([CEODate]) Then

Else
MsgBox "This record is closed. Please contact the Database
Administrator or Quality Manager if you need to edit this record"
End If

End Function

:

Also, what are you clicking on in the combo box: the box itself, or
the
arrow to the right?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message
What's the code in the function?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


"Secret Squirrel" <[email protected]>
wrote
in
message
Actually I do have one follow up question. I put the function
name
in
all
the
"OnClick" events for all my controls but it doesn't seem to work
for
combo
boxes. Should I be doing something different for those?

:

Make sure that your existing module is a function, not a sub.
(It
doesn't
matter whether or not the function returns any value. In fact,
even
if
it
does, the value that's returned isn't going to be usable in
what
follows).

Select all of the controls on the form for which you want the
function
above
to apply. (Remember: not all controls have an OnClick event...)
You
do
this
selection by "lassoing" the relevant controls using your mouse,
or
by
holding down the Shift key while you click on the controls
one-by-one,
or a
combination of the two.

Once you've selected all of the controls of interest, look at
the
Properties
window. It's only going to display properties that exist for
all
of
the
selected controls. If you did your selection properly (i.e.: if
you
didn't
accidentally select a control that doesn't have an OnClick
event),
you
should see the OnClick event in the Properties window. Simply
type
=MyFunctionName() in the property box beside that event name,
and
it
will
apply to all of the selected controls. (In other words, it will
put
it
in
the OnClick event of all 50 controls at once)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


"Secret Squirrel" <[email protected]>
wrote
in
message
Hi Tina,
I read that thread but I'm not sure I understand how to set
that
up. I
already have the msgbox function in my forms module. I just
don't
know
how
to
tie it into all the "On Click" events of all my controls so
that
it
appears
when the record is locked due to a date in one of my
controls.

:

the thread at
http://groups.google.com/group/micr...ss*+author:tina&rnum=1&hl=en#69089e7d34b618a3
explains how to set up a function call from the same event
of
multiple
controls in a form, all at once. note that if you're only
using
the
"msgbox
function" in one form, you can keep the function in that
form's
module -
you
don't have to add it to a standard module (that part of the
thread's
instructions was specific to the situation at hand).

hth


"Secret Squirrel" <[email protected]>
wrote
in
message
I have a control on my form that locks a particular record
when
it
is
populated with a date. When that record is locked and a
user
clicks
in
a
field I want a message box to appear telling them that the
record
is
locked
and cannot be edited. I created a function with my msgbox
so
that I
can
have
all my controls point to but since I have close to 50
controls
is
there
an
easier way to have all the fields point to this function
instead
of
putting
code in each of the "On Click" events of all my controls?
 
Hi Doug.

I read your post and I'm doing basically the same thing, however my
function call needs a variable, namley the value of the control I'm on.
Here's what I'm doing:

Function CheckNumber(dblNumber as Double) as Boolean
CheckNumber=True
If dblNumber > 999 or dblNumber < -999 then
msgbox("Error")
Cancel=true
CheckNumber=False
End If
End Function

My function call within the properties window:
Before Update -
=CheckNumber([controlName])

I need the control name to be the control that I'm on. I could put
this function call in all my controls and change the control name
everytime, but isnt't there a way to pass the value of the control that
triggered the event? Something like =CheckNumber(Me.Control)

Thanks for the original post.

- Mark
 

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


Back
Top