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

How to test if cursor is in text box?

P: n/a
I have a form that I do *not* want the user to be able to use the
PageUp/PageDown keys *unless* the cursor is in a particular text box.

I'm using this code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 33, 34
KeyCode = 0
End Select
Exit Sub

But how do I allow use of the PageUp/PageDown keys within a particular text
box? The text box in question - txtNoteText - will contain a lot of text,
perhpas a few pages, that is populated from a memo field.

Thanks in advance.

I would also like to be able to use the mouse wheel to scroll in the text
box, but I am not sure if this is possible. I am using Stephen Lebans
MouseHook DLL, which turns off the mouse wheel in the form, but I cannot get
it to turn back on when the cursor is in the text box

I tried the below code, but it does not work. I would settle for use of the
PageUp / PageDown Key, however...

Private Sub txtNoteText_Enter()
Dim blRet As Boolean
blRet = MouseWheelON
End Sub

Private Sub txtNoteText_Exit(Cancel As Integer)
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
To see what the currently active control is, try:
Screen.ActiveControl

Be sure to use error handling. Lots can go wrong trying to read that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"deko" <no****@hotmail.com> wrote in message
news:Tv*******************@newssvr25.news.prodigy. com...
I have a form that I do *not* want the user to be able to use the
PageUp/PageDown keys *unless* the cursor is in a particular text box.

I'm using this code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 33, 34
KeyCode = 0
End Select
Exit Sub

But how do I allow use of the PageUp/PageDown keys within a particular text box? The text box in question - txtNoteText - will contain a lot of text,
perhpas a few pages, that is populated from a memo field.

Thanks in advance.

I would also like to be able to use the mouse wheel to scroll in the text
box, but I am not sure if this is possible. I am using Stephen Lebans
MouseHook DLL, which turns off the mouse wheel in the form, but I cannot get it to turn back on when the cursor is in the text box

I tried the below code, but it does not work. I would settle for use of the PageUp / PageDown Key, however...

Private Sub txtNoteText_Enter()
Dim blRet As Boolean
blRet = MouseWheelON
End Sub

Private Sub txtNoteText_Exit(Cancel As Integer)
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
End Sub

Nov 13 '05 #2

P: n/a
> To see what the currently active control is, try:
Screen.ActiveControl


Thanks - that seems to work. But the problem now is that after the current
record is scrolled to the bottom of the field, the form jumps to the next
record, which is the behavior I'm trying to avoid. Here is the code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo HandleErr
Select Case KeyCode
Case 33, 34
If Screen.ActiveControl <> Me.txtNoteText Then KeyCode = 0
End Select
[code omitted]
End Sub

Is there a way to prevent the form from moving to the next record?

By the way, the RecordSource for this form is built form a cloned recordset:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo HandleErr
Dim strNid As String
Dim lngNid As Long
Dim rst As DAO.Recordset
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
If Me.OpenArgs = "OldNote" Then
lngNid = Forms!frm0!frm0Notes.Form!Note_ID
strNid = "Note_ID = " & lngNid
Me.RecordSource = "qryNotesEntity"
Set rst = Me.RecordsetClone
rst.FindFirst strNid
Me.Bookmark = rst.Bookmark
Me.NavigationButtons = True
ElseIf Me.OpenArgs = "NewNote" Then
Me.NavigationButtons = False
End If
Me!txtNoteText.SetFocus
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr ("frmNotesDetail"), ("Form_Open")
End Select
Resume Exit_Here
End Sub
Nov 13 '05 #3

P: n/a
Try setting the form's Cycle property to Current Record.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"deko" <no****@hotmail.com> wrote in message
news:14*******************@newssvr25.news.prodigy. com...
To see what the currently active control is, try:
Screen.ActiveControl
Thanks - that seems to work. But the problem now is that after the

current record is scrolled to the bottom of the field, the form jumps to the next
record, which is the behavior I'm trying to avoid. Here is the code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo HandleErr
Select Case KeyCode
Case 33, 34
If Screen.ActiveControl <> Me.txtNoteText Then KeyCode = 0
End Select
[code omitted]
End Sub

Is there a way to prevent the form from moving to the next record?

By the way, the RecordSource for this form is built form a cloned recordset:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo HandleErr
Dim strNid As String
Dim lngNid As Long
Dim rst As DAO.Recordset
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
If Me.OpenArgs = "OldNote" Then
lngNid = Forms!frm0!frm0Notes.Form!Note_ID
strNid = "Note_ID = " & lngNid
Me.RecordSource = "qryNotesEntity"
Set rst = Me.RecordsetClone
rst.FindFirst strNid
Me.Bookmark = rst.Bookmark
Me.NavigationButtons = True
ElseIf Me.OpenArgs = "NewNote" Then
Me.NavigationButtons = False
End If
Me!txtNoteText.SetFocus
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr ("frmNotesDetail"), ("Form_Open")
End Select
Resume Exit_Here
End Sub

Nov 13 '05 #4

P: n/a
The default behaviour for the MouseWHeelOff method is to allow the use
of the MouseWheel within a TextBox control that contains ScrollBars. You
do not need to Start/Stop the MouseHook each time you enter a TexBox
control.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
To see what the currently active control is, try:
Screen.ActiveControl

Be sure to use error handling. Lots can go wrong trying to read that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"deko" <no****@hotmail.com> wrote in message
news:Tv*******************@newssvr25.news.prodigy. com...
I have a form that I do *not* want the user to be able to use the
PageUp/PageDown keys *unless* the cursor is in a particular text box.
I'm using this code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 33, 34
KeyCode = 0
End Select
Exit Sub

But how do I allow use of the PageUp/PageDown keys within a particular
text
box? The text box in question - txtNoteText - will contain a lot of
text, perhpas a few pages, that is populated from a memo field.

Thanks in advance.

I would also like to be able to use the mouse wheel to scroll in the text box, but I am not sure if this is possible. I am using Stephen Lebans MouseHook DLL, which turns off the mouse wheel in the form, but I

cannot get
it to turn back on when the cursor is in the text box

I tried the below code, but it does not work. I would settle for
use of the
PageUp / PageDown Key, however...

Private Sub txtNoteText_Enter()
Dim blRet As Boolean
blRet = MouseWheelON
End Sub

Private Sub txtNoteText_Exit(Cancel As Integer)
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
End Sub



Nov 13 '05 #5

P: n/a
> Try setting the form's Cycle property to Current Record.

It is currently set that way. I also tried Current Page, but that did not
help. Is this problem due to a limitation with the control itself? Is
there some other control (other than a text box) that may be better for
multiple pages of text? A control that will accomodate Rich Text would be
nice, but scrolling with the Mouse Wheel, or at least the PageUp/PageDown
keys, is all that is really necessary. One caveat - I need to keep the
control unbound. There is a reason I need to use a cloned recordset to
build the RecordSource for the form.

Nov 13 '05 #6

P: n/a
> The default behaviour for the MouseWHeelOff method is to allow the use
of the MouseWheel within a TextBox control that contains ScrollBars. You
do not need to Start/Stop the MouseHook each time you enter a TexBox
control.


Hi and thanks for the reply. Yes, I remember reading about this on your
site. Unfortunately, it's not working that way in this case. The reason
for this, I think, is because either the control is unbound, or because I am
using a cloned recordset. At least those are the only tow differences from
other forms. Here is the Form_Open code, which builds the cloned recordset
from a query, which is the form's RecordSource.

Private Sub Form_Open(Cancel As Integer)
On Error GoTo HandleErr
Dim strNid As String
Dim lngNid As Long
Dim rst As DAO.Recordset
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
If Me.OpenArgs = "OldNote" Then
lngNid = Forms!frm0!frm0Notes.Form!Note_ID
strNid = "Note_ID = " & lngNid
Me.RecordSource = "qryNotesEntity"
Set rst = Me.RecordsetClone
rst.FindFirst strNid
Me.Bookmark = rst.Bookmark
Me.NavigationButtons = True
ElseIf Me.OpenArgs = "NewNote" Then
Me.NavigationButtons = False
End If
Me!txtNoteText.SetFocus
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr ("frmNotesDetail"), ("Form_Open")
End Select
Resume Exit_Here
End Sub
Nov 13 '05 #7

P: n/a
It makes absolutely no difference is the TextBox control is unbound or
that you have cloned the recordsource.

1) Place the call to MouseWHeelOff in the Form's Load event as shown in
the sample code.

2) Verify that the return value from the call to MouseWHeelOff is =
TRUE.

Let me know.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"deko" <no****@hotmail.com> wrote in message
news:IV*****************@newssvr27.news.prodigy.co m...
The default behaviour for the MouseWHeelOff method is to allow the use of the MouseWheel within a TextBox control that contains ScrollBars. You do not need to Start/Stop the MouseHook each time you enter a TexBox
control.
Hi and thanks for the reply. Yes, I remember reading about this on

your site. Unfortunately, it's not working that way in this case. The reason for this, I think, is because either the control is unbound, or because I am using a cloned recordset. At least those are the only tow differences from other forms. Here is the Form_Open code, which builds the cloned recordset from a query, which is the form's RecordSource.

Private Sub Form_Open(Cancel As Integer)
On Error GoTo HandleErr
Dim strNid As String
Dim lngNid As Long
Dim rst As DAO.Recordset
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
If Me.OpenArgs = "OldNote" Then
lngNid = Forms!frm0!frm0Notes.Form!Note_ID
strNid = "Note_ID = " & lngNid
Me.RecordSource = "qryNotesEntity"
Set rst = Me.RecordsetClone
rst.FindFirst strNid
Me.Bookmark = rst.Bookmark
Me.NavigationButtons = True
ElseIf Me.OpenArgs = "NewNote" Then
Me.NavigationButtons = False
End If
Me!txtNoteText.SetFocus
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr ("frmNotesDetail"), ("Form_Open")
End Select
Resume Exit_Here
End Sub


Nov 13 '05 #8

P: n/a
> It makes absolutely no difference is the TextBox control is unbound or
that you have cloned the recordsource.

1) Place the call to MouseWHeelOff in the Form's Load event as shown in
the sample code.

2) Verify that the return value from the call to MouseWHeelOff is =
TRUE.


Okay, I put the call to MouseWheelOff in the Form's Load event and tried
this:

Private Sub Form_Load()
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
Debug.Print MouseWheelOFF
End Sub

The result I get in the immediate wiwdow is "False", but the mouse wheel
behaves properly - that is, it is disabled or enabled according to the code.

The scrolling problem with the PageUp/PageDown keys is that the form moves
to the next record (not desired) - even if the form's Cycle property is set
to Current Record. But the text (in the text box of the current record)
will scroll to the bottom (desired). The jump to the next record happens
when the text box reaches the end of the text.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 33, 34
If Screen.ActiveControl <> Me.txtNoteText Then KeyCode = 0
End Select
End Sub

If I enable the mouse wheel, the text within the text box does *not* scroll,
but the form moves to the next record when attempting to scroll - which is
the behavior I am trying to avoid (while allowing scrolling of the text in
the text box).

I may just try to re-create the entire form... I'm lost here...
Nov 13 '05 #9

P: n/a
Your Debug.Print statement is ending up calling the MouseWheelOff
function again. Debug.Print the returned Boolean variable instead.
I emailed you back that the MDB you sent me will not function as it. It
is imissing a Query and a custom function for error handling etc. Send
me a working MDB and I will debug this for you as the MouseWheelHook
will give you the desired functionality.
:-)

BTW, what version of Access are you using?
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"deko" <no****@hotmail.com> wrote in message
news:15*****************@newssvr27.news.prodigy.co m...
It makes absolutely no difference is the TextBox control is unbound or that you have cloned the recordsource.

1) Place the call to MouseWHeelOff in the Form's Load event as shown in the sample code.

2) Verify that the return value from the call to MouseWHeelOff is =
TRUE.
Okay, I put the call to MouseWheelOff in the Form's Load event and

tried this:

Private Sub Form_Load()
Dim blRet As Boolean
blRet = MouseWheelOFF(False)
Debug.Print MouseWheelOFF
End Sub

The result I get in the immediate wiwdow is "False", but the mouse wheel behaves properly - that is, it is disabled or enabled according to the code.
The scrolling problem with the PageUp/PageDown keys is that the form moves to the next record (not desired) - even if the form's Cycle property is set to Current Record. But the text (in the text box of the current record) will scroll to the bottom (desired). The jump to the next record happens when the text box reaches the end of the text.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 33, 34
If Screen.ActiveControl <> Me.txtNoteText Then KeyCode = 0
End Select
End Sub

If I enable the mouse wheel, the text within the text box does *not* scroll, but the form moves to the next record when attempting to scroll - which is the behavior I am trying to avoid (while allowing scrolling of the text in the text box).

I may just try to re-create the entire form... I'm lost here...


Nov 13 '05 #10

P: n/a
> BTW, what version of Access are you using?

Access 2003

updated mdb on the way...
Nov 13 '05 #11

P: n/a
When you mentioned the Vertical ScrollBar was not visible this was
obviously the problem. With no Vertical ScrollBar there are no
MouseWHeel messages available for my MouseHook to process.
Looks like another A2003 bug. If you set the TextBox Top or Bottom
Margin props then Vertical ScrollBar will not appear! I've reported the
bug. For now simply leave off the Margin settings.
:-)

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"deko" <no****@hotmail.com> wrote in message
news:NZ*******************@newssvr25.news.prodigy. com...
BTW, what version of Access are you using?


Access 2003

updated mdb on the way...


Nov 13 '05 #12

P: n/a
> When you mentioned the Vertical ScrollBar was not visible this was
obviously the problem. With no Vertical ScrollBar there are no
MouseWHeel messages available for my MouseHook to process.
Looks like another A2003 bug. If you set the TextBox Top or Bottom
Margin props then Vertical ScrollBar will not appear! I've reported the
bug. For now simply leave off the Margin settings.
:-)


yep, that was it... I set the textbox margins to 0 - now the mouse wheel
works and the scrollbar is there. I'll keep an eye out for the KB article
:)

Thanks again for the help.
Nov 13 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.