No. By the time the command button's event runs, it has focus, so there is
no chance of then determining where in Screen.PreviousControl the cursor was
previously placed.
Use a toolbar button instead. (Or you could get the same effect from a popup
form.)
Unfortunately, a command button on this continuous form is more convenient.
What do you think of using the OnEnter event of each control (except the
command button, naturally) to write the name or index to a textbox?
Create a function with a static varialbe:
Private Function WhereWasI() As String
Static strLastAt As String
If Screen.ActiveControl.Name <> "CmdMyCommandButton" Then
strLastAt = Screen.ActiveControl.Name
End If
WhereWasI = strLastAt
End Function
Then in the Enter event (or got focus)
=WhereWasI()
As Allen pointed out, you can get a reference to the previous control using:
Screen.PreviousControl
I'm assuming that Allen assumed (like me) that "where the cursor last was"
meant the actual x-y coordinates of the cursor, not simply the active
control.
I know that, but perhaps is because of Allen's post that I thought there was
a problem with it that I was not aware of. Just using Screen.PreviousControl
is better.
If you just wanted to know which control had focus before the command
button, Screen.PreviousControl should do. Be sure to use error-handling:
I've always found Screen.PreviousControl a little flakey, so I tend to put
it in a separate function so it doesn't muck up the main one.
Doug is right: I assumed the command button was doing something like,
"Insert boilerplate text at the cursor position in the previous control."
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.