By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,663 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,663 IT Pros & Developers. It's quick & easy.

Checking For Click Event of Command Button During LostFocus Event

P: n/a
MJW
Is there a way for me to know if or which command button was just
clicked that triggers the LostFocus event for the current control on a
Form?

I have a form that has many types of users who each have their own set
of fields they can change. Therefore I use setfocus property in the
lostfocus event for some of the users to get from one control to
another. Since I am "directing traffic" with setfocus, the users are
unable to use the record navigation buttons I created to go back and
forth between records. The user presses the GetPreviousRecord button,
the lostfocus event of the current control is triggered, and the
setfocus code forces the user to the next control ignoring that the
user wants to go to the next record. How can I determine that I
pressed the GetPreviousRecord button so I can go to the previous
record and ignore the setfocus code for the next control?

From MS help under lostfocus event:
If you move the focus to a control on a form, and that control doesn't
have the focus on that form, the Exit and LostFocus events for the
control that does have the focus on the form occur before the Enter
and GotFocus events for the control you moved to.

Is there anyway I can see the control that is going to get the Enter
Event before exiting the current control?

Thanks for your help!
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You can use the ActiveControl property of the Screen object to figure out
which button was just pressed. Here is an example:
If Screen.ActiveControl.Name = "cmdPreviousRecord" Then
Nov 12 '05 #2

P: n/a
There is no way to know which control is about to receive focus.

Once focus has moved to the command button, Screen.PreviousControl will tell
you where it came from.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"MJW" <mw*****@designid.com> wrote in message
news:1b*************************@posting.google.co m...
Is there a way for me to know if or which command button was just
clicked that triggers the LostFocus event for the current control on a
Form?

I have a form that has many types of users who each have their own set
of fields they can change. Therefore I use setfocus property in the
lostfocus event for some of the users to get from one control to
another. Since I am "directing traffic" with setfocus, the users are
unable to use the record navigation buttons I created to go back and
forth between records. The user presses the GetPreviousRecord button,
the lostfocus event of the current control is triggered, and the
setfocus code forces the user to the next control ignoring that the
user wants to go to the next record. How can I determine that I
pressed the GetPreviousRecord button so I can go to the previous
record and ignore the setfocus code for the next control?

From MS help under lostfocus event:
If you move the focus to a control on a form, and that control doesn't
have the focus on that form, the Exit and LostFocus events for the
control that does have the focus on the form occur before the Enter
and GotFocus events for the control you moved to.

Is there anyway I can see the control that is going to get the Enter
Event before exiting the current control?

Thanks for your help!

Nov 12 '05 #3

P: n/a
MJW
Thank you for responding. This will not work for me in this case
because I want to know which command button was pressed that triggers
the lostfocus event of the current control (textbox) that I am in. so
Screen.ActiveControl.Name will tell me the name of the control that I
am currently on, not the command button I just pressed (I tried this
before I sent the post.)

"Tom marsh" <le*******@goodwill-suncoast.com> wrote in message news:<7M*****************@twister.tampabay.rr.com> ...
You can use the ActiveControl property of the Screen object to figure out
which button was just pressed. Here is an example:
If Screen.ActiveControl.Name = "cmdPreviousRecord" Then
.
. ' Do something here
.
ElseIf Screen.ActiveControl.Name = "txtCustomerName" Then
.
. ' Do something else.
.
End If

Hope this helps.
"MJW" <mw*****@designid.com> wrote in message
news:1b*************************@posting.google.co m...
Is there a way for me to know if or which command button was just
clicked that triggers the LostFocus event for the current control on a
Form?

I have a form that has many types of users who each have their own set
of fields they can change. Therefore I use setfocus property in the
lostfocus event for some of the users to get from one control to
another. Since I am "directing traffic" with setfocus, the users are
unable to use the record navigation buttons I created to go back and
forth between records. The user presses the GetPreviousRecord button,
the lostfocus event of the current control is triggered, and the
setfocus code forces the user to the next control ignoring that the
user wants to go to the next record. How can I determine that I
pressed the GetPreviousRecord button so I can go to the previous
record and ignore the setfocus code for the next control?

From MS help under lostfocus event:
If you move the focus to a control on a form, and that control doesn't
have the focus on that form, the Exit and LostFocus events for the
control that does have the focus on the form occur before the Enter
and GotFocus events for the control you moved to.

Is there anyway I can see the control that is going to get the Enter
Event before exiting the current control?

Thanks for your help!

Nov 12 '05 #4

P: n/a
MJW
That is what I was afraid of. Since my lostfocus event has a setfocus
to a different textbox, the command button pressed is ignored and the
focus moves to the textbox instead.

Thanks for responding.
"Allen Browne" <ab***************@bigpond.net.au> wrote in message news:<uH********************@news-server.bigpond.net.au>...
There is no way to know which control is about to receive focus.

Once focus has moved to the command button, Screen.PreviousControl will tell
you where it came from.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"MJW" <mw*****@designid.com> wrote in message
news:1b*************************@posting.google.co m...
Is there a way for me to know if or which command button was just
clicked that triggers the LostFocus event for the current control on a
Form?

I have a form that has many types of users who each have their own set
of fields they can change. Therefore I use setfocus property in the
lostfocus event for some of the users to get from one control to
another. Since I am "directing traffic" with setfocus, the users are
unable to use the record navigation buttons I created to go back and
forth between records. The user presses the GetPreviousRecord button,
the lostfocus event of the current control is triggered, and the
setfocus code forces the user to the next control ignoring that the
user wants to go to the next record. How can I determine that I
pressed the GetPreviousRecord button so I can go to the previous
record and ignore the setfocus code for the next control?

From MS help under lostfocus event:
If you move the focus to a control on a form, and that control doesn't
have the focus on that form, the Exit and LostFocus events for the
control that does have the focus on the form occur before the Enter
and GotFocus events for the control you moved to.

Is there anyway I can see the control that is going to get the Enter
Event before exiting the current control?

Thanks for your help!

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.