Hiding "text select" cursor OnEnter Text Box

  • Thread starter Thread starter CES
  • Start date Start date
C

CES

All,
I was wondering if there was a way of hiding the text select cursor when a text box gets focus in Access 2007? Basically what I'm looking for is to hide the blinking cursor when ever the text box has focus.

I found two examples of calling the Windows API:

I was able to get the first one, which hides the mouse cursor working...

Public Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long


But unfortunately I think the one that will accomplish my task "HideCaret"(???) doesn't seem to want to cooperate.

--- this is in a module ---

Public Declare Function HideCaret Lib "user32" (ByVal hwnd As Long) As Long

Public Function ShowPointer()
Do While HideCaret(1) < 0
DoEvents
Loop
End Function

Public Function HidePointer()
Do While HideCaret(0) >= -1
DoEvents
Loop
End Function

--- this is in the form ---

Private Sub Text7_Enter()
Call HidePointer
End Sub


As I stated on not even sure if "HideCaret is the right API Call? If anyone has a clue how to accomplish my goal I would appreciate your advice. Thanks in advance. - CES
 
Hello CES,

HideCaret needs a handle of the window:

bool HideCaret(IntPtr hWnd);

Since 0/1 is not the valid window handle of text7, the function doesn't
have any effect. Unlike the controls in VB6 Forms, VBA controls in
UserForms are windowless and therefore don't have a window handle.
Therefor, this API might not be used properly in Access.

If you have any further questioins or concerns, please feel free to let's
know. Thank you.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications
<http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx>.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
<http://msdn.microsoft.com/subscriptions/support/default.aspx>.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Since Peter has teased you by indicating how you *might* be able to do it,
I'll continue his work by showing how you *can* do it.

The first thing you need to know is that what Peter said is half right.
Access controls are windowless until they have keyboard focus. Since they
are windowless, they don't have a hWnd property as do VB controls. But, when
they have the focus, you can use the GetFocus() API to return its hWnd. Once
you have the nWnd, you can use HideCaret() API to, well, hide the caret.

The probem in your scenario is that two things can happen. If you simply tab
into the textbox, you can then call HideCaret(), and all will work OK. But
if you click into it, the GotFocus event will fire and the caret will be
terminated, but then the mouse events will fire and undo all your good work.
So I suggest calling HideCaret() from both events.

Put the following into a standard module:
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As Long) As
Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

Put the following into the GotFocus property (the property - not the event
procedure) of every control whose caret should be hidden:
=HidePointer()

Put the same into the control's MouseUp property (the property - not the
event procedure) :
=HidePointer()

Keep in mind, I only did a cursory test (pun intended) of the above. I did
not do exhaustive testing, so as Peter suggests, it may or may not work
properly in Access.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Graham said:
Since Peter has teased you by indicating how you *might* be able to do
it, I'll continue his work by showing how you *can* do it.

The first thing you need to know is that what Peter said is half right.
Access controls are windowless until they have keyboard focus. Since
they are windowless, they don't have a hWnd property as do VB controls.
But, when they have the focus, you can use the GetFocus() API to return
its hWnd. Once you have the nWnd, you can use HideCaret() API to, well,
hide the caret.

The probem in your scenario is that two things can happen. If you simply
tab into the textbox, you can then call HideCaret(), and all will work
OK. But if you click into it, the GotFocus event will fire and the caret
will be terminated, but then the mouse events will fire and undo all
your good work. So I suggest calling HideCaret() from both events.

Put the following into a standard module:
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As Long)
As Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

Put the following into the GotFocus property (the property - not the
event procedure) of every control whose caret should be hidden:
=HidePointer()

Put the same into the control's MouseUp property (the property - not the
event procedure) :
=HidePointer()

Keep in mind, I only did a cursory test (pun intended) of the above. I
did not do exhaustive testing, so as Peter suggests, it may or may not
work properly in Access.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
Graham,

Thank you for your help, it works as advertised with one caveat... unfortunately the text box is the only element on the form that has Tab Stop enabled. While the text box works properly after you've done something on the form, such as move to the next record, when it initially gets focus its still shows the Caret.

Is there a way of setting HidePointer when the form initially loads?

Also this is the first time that I've run into placing =SomeFunction() in an event property and I'm not exactly sure what the difference is between calling the function this way or

Private Sub control GotFocus()
Call SomeFunction
End Sub

It seems to me they both do the same thing? Thanks for your guidance. - CES
 
Placing a value in the event property is functionally the same as writing a
line of code within an event procedure, however, if you want to call the
same procedure (or macro) from several controls on your form, it's far
quicker than writing code for each procedure. For example, in form design
view, you can select several controls at once, and enter a function name
into the event property, and it will automatically apply to *all* the
controls you've selected. The problem is (if you want to call it a problem)
that the procedure name you enter in the property MUST be a function - not a
sub, and it must be public, not private.

As for your remaining problem, I might suggest that you call
SetFocus/GetFocus/HideCaret from within the form's Current event. That
should take care of the initial caret visibility issue.

I still have to ask - why don't you like the caret? What did it ever do to
you? ;-)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Graham's last line echoes the concensus opinion when this question arises
from time to time; why don't you want the user to know where he/she is at in
the form? Without the "blinking cursor" how would they know where they are
within the text if they're trying to do a correction, i.e. delete or replace
a character in a mispelled word, for instance?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
Graham said:
Placing a value in the event property is functionally the same as
writing a line of code within an event procedure, however, if you want
to call the same procedure (or macro) from several controls on your
form, it's far quicker than writing code for each procedure. For
example, in form design view, you can select several controls at once,
and enter a function name into the event property, and it will
automatically apply to *all* the controls you've selected. The problem
is (if you want to call it a problem) that the procedure name you enter
in the property MUST be a function - not a sub, and it must be public,
not private.

As for your remaining problem, I might suggest that you call
SetFocus/GetFocus/HideCaret from within the form's Current event. That
should take care of the initial caret visibility issue.

I still have to ask - why don't you like the caret? What did it ever do
to you? ;-)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
Graham,
I'm not exactly sure what is meant when you say "call SetFocus/GetFocus/HideCaret from within the form's Current event" you mean

Private Sub Form_Current()
Me.Control.SetFocus
Me.Control.OnEnter = HidePointer() 'Has no effect... Doesn't this just assign HidePointer() to the OnEnter event of the control??
etc.

Call HidePointer 'has no effect
Call Any sub Control_GotFocus() ' throws an error
End Sub

- CES
 
Sorry for not getting back to you earlier; I've been really busy.

It's hard to know people's level of expertise. I worked on the assumption
that you had enough knowledge to be able to follow what I was saying. Not to
worry. Let's start again.

1. Create a new module, and put the following at the top of it, below where
it says "Option Explicit". (If it doesn't say that at the top, write it in).
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As Long) As
Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

2. Open your form in design view. Display the Properties dialog (View |
Properties). Select the Events tab.

3. Select the control whose caret you want to hide.

4. Where the Properties dialog says [On Got Focus], enter the following text
(including the = sign):
=HidePointer()

5. Do the same for [On Mouse Up].

6. Repeat Steps 3, 4 & 5 for each control whose caret you want to hide.

5. Select "Form" from the [Selection Type] in the Properties dialog. Then
enter the following into [On Curent]:
=HidePointer()

6. Save the form.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Graham said:
Sorry for not getting back to you earlier; I've been really busy.

It's hard to know people's level of expertise. I worked on the
assumption that you had enough knowledge to be able to follow what I was
saying. Not to worry. Let's start again.

1. Create a new module, and put the following at the top of it, below
where it says "Option Explicit". (If it doesn't say that at the top,
write it in).
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As Long)
As Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

2. Open your form in design view. Display the Properties dialog (View |
Properties). Select the Events tab.

3. Select the control whose caret you want to hide.

4. Where the Properties dialog says [On Got Focus], enter the following
text (including the = sign):
=HidePointer()

5. Do the same for [On Mouse Up].

6. Repeat Steps 3, 4 & 5 for each control whose caret you want to hide.

5. Select "Form" from the [Selection Type] in the Properties dialog.
Then enter the following into [On Curent]:
=HidePointer()

6. Save the form.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


CES said:
Graham,
I'm not exactly sure what is meant when you say "call
SetFocus/GetFocus/HideCaret from within the form's Current event" you
mean

Private Sub Form_Current()
Me.Control.SetFocus
Me.Control.OnEnter = HidePointer() 'Has no effect... Doesn't this just
assign HidePointer() to the OnEnter event of the control??
etc.

Call HidePointer 'has no effect
Call Any sub Control_GotFocus() ' throws an error
End Sub

- CES

Graham,
thank you for getting back with me... unfortunately the problem is not with my inexperience with VBS, this time.

I wanted to make sure that there wasn't some other code causing the problem so I created a new access file to test out. You can find the file at:

http://209.132.211.66/files/file.accdb

If you download the file you what find that I've done as suggested. Unfortunately the problem persists when the form initaly loads... any subsequent action on the form will indeed caused the caret to hide properly but the action of initially displaying the form does not produce the desired effect.

FYI - I've tried placing =HidePointer() in other Form Events Form_Load(),Sub Form_Open, Form_GotFocus() besides Form_Current() but they too do not hide the caret on the forms of initial open.

Re: calling =HidePointer() on a form event such as onCurrent - I'm not exactly sure why doing this would cause the textbox to evoke the method, because it doesn't receive focus until after the Form_Current() Event has been executed? If I were to call the method this way wouldn't that cause the caret to be hidden on form itself and not any control?

Additionally I can't use =HidePointer() as you indicated because I have other methods that need to be called in the Form_Current() Event how would you call the method within a Sub routine.

Private Sub Form_Current()

Call HidePointer
Call OtherMethods

End Sub

In any event I really appreciate your time and effort, thank you - CES
 
CES said:
Graham,
thank you for getting back with me... unfortunately the problem is not
with my inexperience with VBS, this time.

I wanted to make sure that there wasn't some other code causing the
problem so I created a new access file to test out. You can find the file
at:

http://209.132.211.66/files/file.accdb

If you download the file you what find that I've done as suggested.
Unfortunately the problem persists when the form initaly loads... any
subsequent action on the form will indeed caused the caret to hide
properly but the action of initially displaying the form does not produce
the desired effect.

FYI - I've tried placing =HidePointer() in other Form Events
Form_Load(),Sub Form_Open, Form_GotFocus() besides Form_Current() but they
too do not hide the caret on the forms of initial open.


fwiw, jumping in mid-thread here, so no clue what language this is (VB
Classic has no such events), but can't you simply set the visibility of that
textbox = False, thereby forcing focus to shift to the next available
control, until the form is ready for use?
 
Ken said:
fwiw, jumping in mid-thread here, so no clue what language this is (VB
Classic has no such events), but can't you simply set the visibility of that
textbox = False, thereby forcing focus to shift to the next available
control, until the form is ready for use?

Ken,
I'm not trying to set the visibility of the textBox I'm trying to hide the blinking cursor within the text box... - CES
 
CES said:
Ken,
I'm not trying to set the visibility of the textBox I'm trying to hide the
blinking cursor within the text box... - CES

That much I can see.... since it's not VB though, I can't provide a
solution... the thing is, hiding that box >should< remove any selection or
appearance of a selection. Then, show it again. In other words, hiding the
box is simply robbing it of focus, temporarily. When you show it again, if
it were a VB textbox, there should be no selected text... unless, the
GotFocus event of that textbox is selecting the text itself... in which
case, comment that stuff out.
 
Ken said:
That much I can see.... since it's not VB though, I can't provide a
solution... the thing is, hiding that box >should< remove any selection or
appearance of a selection. Then, show it again. In other words, hiding the
box is simply robbing it of focus, temporarily. When you show it again, if
it were a VB textbox, there should be no selected text... unless, the
GotFocus event of that textbox is selecting the text itself... in which
case, comment that stuff out.
Sorry I didn't understand your suggestion... unfortunately it's the only control on the form that is enabled and as such can receive focus, trying to set focus somewhere else would produce in error. However the problem is not with the controls focus. After your post I create a second tmp field:

Private Sub Form_Current()
Me.temp2.SetFocus
Me.temp1.SetFocus
End Sub

after giving focus to the second control, it then sets focus back to the original control. Unfortunately the problem still persists, when Me.temp1 receives focus back from Me.temp2 The Cursor\Caret still blinks.

Once again the only time that I see this behavior is when the form initially loads otherwise the caret is hidden. - CES
 
Hello,

First I'd thanks Graham for sharing the knowledge of getting handle by
getfocus API.

CES, I think you may try to set time interval property of form to 1000, and
try to use following to hide cursor for the situation

Private Sub Form_Timer()
Call HidePointer

End Sub

Hope this is helpful.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=====================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi again,

Again I apologise for not getting back to you sooner; I've been in the bush
for a week, with no access to the Internet.

I have checked and double checked, and calling =HidePointer() from [On Got
Focus] and [On Mouse Up] works for me every time without fail. It should
work for you also.

Given that you report it doesn't, I sugest that there is some code running
which steals focus control and then (behind the scenes) replaces it. Check
your form startup code step-by-step, visually checking the controls' focus
all the while. That will uncover the culprit.

After you know where the problem is, you can add a line of code to call
HidePointer().

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


CES said:
Graham said:
Sorry for not getting back to you earlier; I've been really busy.

It's hard to know people's level of expertise. I worked on the assumption
that you had enough knowledge to be able to follow what I was saying. Not
to worry. Let's start again.

1. Create a new module, and put the following at the top of it, below
where it says "Option Explicit". (If it doesn't say that at the top,
write it in).
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As Long) As
Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

2. Open your form in design view. Display the Properties dialog (View |
Properties). Select the Events tab.

3. Select the control whose caret you want to hide.

4. Where the Properties dialog says [On Got Focus], enter the following
text (including the = sign):
=HidePointer()

5. Do the same for [On Mouse Up].

6. Repeat Steps 3, 4 & 5 for each control whose caret you want to hide.

5. Select "Form" from the [Selection Type] in the Properties dialog. Then
enter the following into [On Curent]:
=HidePointer()

6. Save the form.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


CES said:
Graham R Seach wrote:
Placing a value in the event property is functionally the same as
writing a line of code within an event procedure, however, if you want
to call the same procedure (or macro) from several controls on your
form, it's far quicker than writing code for each procedure. For
example, in form design view, you can select several controls at once,
and enter a function name into the event property, and it will
automatically apply to *all* the controls you've selected. The problem
is (if you want to call it a problem) that the procedure name you enter
in the property MUST be a function - not a sub, and it must be public,
not private.

As for your remaining problem, I might suggest that you call
SetFocus/GetFocus/HideCaret from within the form's Current event. That
should take care of the initial caret visibility issue.

I still have to ask - why don't you like the caret? What did it ever do
to you? ;-)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Graham R Seach wrote:
Since Peter has teased you by indicating how you *might* be able to
do it, I'll continue his work by showing how you *can* do it.

The first thing you need to know is that what Peter said is half
right. Access controls are windowless until they have keyboard focus.
Since they are windowless, they don't have a hWnd property as do VB
controls. But, when they have the focus, you can use the GetFocus()
API to return its hWnd. Once you have the nWnd, you can use
HideCaret() API to, well, hide the caret.

The probem in your scenario is that two things can happen. If you
simply tab into the textbox, you can then call HideCaret(), and all
will work OK. But if you click into it, the GotFocus event will fire
and the caret will be terminated, but then the mouse events will fire
and undo all your good work. So I suggest calling HideCaret() from
both events.

Put the following into a standard module:
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As
Long) As Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

Put the following into the GotFocus property (the property - not the
event procedure) of every control whose caret should be hidden:
=HidePointer()

Put the same into the control's MouseUp property (the property - not
the event procedure) :
=HidePointer()

Keep in mind, I only did a cursory test (pun intended) of the above.
I did not do exhaustive testing, so as Peter suggests, it may or may
not work properly in Access.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

All,
I was wondering if there was a way of hiding the text select cursor
when a text box gets focus in Access 2007? Basically what I'm
looking for is to hide the blinking cursor when ever the text box
has focus.

I found two examples of calling the Windows API:

I was able to get the first one, which hides the mouse cursor
working...

Public Declare Function ShowCursor Lib "user32" (ByVal bShow As
Long) As Long


But unfortunately I think the one that will accomplish my task
"HideCaret"(???) doesn't seem to want to cooperate.

--- this is in a module ---

Public Declare Function HideCaret Lib "user32" (ByVal hwnd As Long)
As Long

Public Function ShowPointer()
Do While HideCaret(1) < 0
DoEvents
Loop
End Function

Public Function HidePointer()
Do While HideCaret(0) >= -1
DoEvents
Loop
End Function

--- this is in the form ---

Private Sub Text7_Enter()
Call HidePointer
End Sub


As I stated on not even sure if "HideCaret is the right API Call? If
anyone has a clue how to accomplish my goal I would appreciate your
advice. Thanks in advance. - CES

Graham,

Thank you for your help, it works as advertised with one caveat...
unfortunately the text box is the only element on the form that has
Tab Stop enabled. While the text box works properly after you've done
something on the form, such as move to the next record, when it
initially gets focus its still shows the Caret.

Is there a way of setting HidePointer when the form initially loads?

Also this is the first time that I've run into placing =SomeFunction()
in an event property and I'm not exactly sure what the difference is
between calling the function this way or

Private Sub control GotFocus()
Call SomeFunction
End Sub

It seems to me they both do the same thing? Thanks for your
guidance. - CES

Graham,
I'm not exactly sure what is meant when you say "call
SetFocus/GetFocus/HideCaret from within the form's Current event" you
mean

Private Sub Form_Current()
Me.Control.SetFocus
Me.Control.OnEnter = HidePointer() 'Has no effect... Doesn't this just
assign HidePointer() to the OnEnter event of the control??
etc.

Call HidePointer 'has no effect
Call Any sub Control_GotFocus() ' throws an error
End Sub

- CES

Graham,
thank you for getting back with me... unfortunately the problem is not
with my inexperience with VBS, this time.

I wanted to make sure that there wasn't some other code causing the
problem so I created a new access file to test out. You can find the file
at:

http://209.132.211.66/files/file.accdb

If you download the file you what find that I've done as suggested.
Unfortunately the problem persists when the form initaly loads... any
subsequent action on the form will indeed caused the caret to hide
properly but the action of initially displaying the form does not produce
the desired effect.

FYI - I've tried placing =HidePointer() in other Form Events
Form_Load(),Sub Form_Open, Form_GotFocus() besides Form_Current() but they
too do not hide the caret on the forms of initial open.

Re: calling =HidePointer() on a form event such as onCurrent - I'm not
exactly sure why doing this would cause the textbox to evoke the method,
because it doesn't receive focus until after the Form_Current() Event has
been executed? If I were to call the method this way wouldn't that cause
the caret to be hidden on form itself and not any control?

Additionally I can't use =HidePointer() as you indicated because I have
other methods that need to be called in the Form_Current() Event how would
you call the method within a Sub routine.

Private Sub Form_Current()

Call HidePointer
Call OtherMethods

End Sub

In any event I really appreciate your time and effort, thank you - CES
 
Graham said:
Hi again,

Again I apologise for not getting back to you sooner; I've been in the
bush for a week, with no access to the Internet.

I have checked and double checked, and calling =HidePointer() from [On
Got Focus] and [On Mouse Up] works for me every time without fail. It
should work for you also.

Given that you report it doesn't, I sugest that there is some code
running which steals focus control and then (behind the scenes) replaces
it. Check your form startup code step-by-step, visually checking the
controls' focus all the while. That will uncover the culprit.

After you know where the problem is, you can add a line of code to call
HidePointer().

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


CES said:
Graham said:
Sorry for not getting back to you earlier; I've been really busy.

It's hard to know people's level of expertise. I worked on the
assumption that you had enough knowledge to be able to follow what I
was saying. Not to worry. Let's start again.

1. Create a new module, and put the following at the top of it, below
where it says "Option Explicit". (If it doesn't say that at the top,
write it in).
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As
Long) As Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

2. Open your form in design view. Display the Properties dialog (View
| Properties). Select the Events tab.

3. Select the control whose caret you want to hide.

4. Where the Properties dialog says [On Got Focus], enter the
following text (including the = sign):
=HidePointer()

5. Do the same for [On Mouse Up].

6. Repeat Steps 3, 4 & 5 for each control whose caret you want to hide.

5. Select "Form" from the [Selection Type] in the Properties dialog.
Then enter the following into [On Curent]:
=HidePointer()

6. Save the form.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Graham R Seach wrote:
Placing a value in the event property is functionally the same as
writing a line of code within an event procedure, however, if you
want to call the same procedure (or macro) from several controls on
your form, it's far quicker than writing code for each procedure.
For example, in form design view, you can select several controls
at once, and enter a function name into the event property, and it
will automatically apply to *all* the controls you've selected. The
problem is (if you want to call it a problem) that the procedure
name you enter in the property MUST be a function - not a sub, and
it must be public, not private.

As for your remaining problem, I might suggest that you call
SetFocus/GetFocus/HideCaret from within the form's Current event.
That should take care of the initial caret visibility issue.

I still have to ask - why don't you like the caret? What did it
ever do to you? ;-)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Graham R Seach wrote:
Since Peter has teased you by indicating how you *might* be able
to do it, I'll continue his work by showing how you *can* do it.

The first thing you need to know is that what Peter said is half
right. Access controls are windowless until they have keyboard
focus. Since they are windowless, they don't have a hWnd property
as do VB controls. But, when they have the focus, you can use the
GetFocus() API to return its hWnd. Once you have the nWnd, you
can use HideCaret() API to, well, hide the caret.

The probem in your scenario is that two things can happen. If you
simply tab into the textbox, you can then call HideCaret(), and
all will work OK. But if you click into it, the GotFocus event
will fire and the caret will be terminated, but then the mouse
events will fire and undo all your good work. So I suggest
calling HideCaret() from both events.

Put the following into a standard module:
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As
Long) As Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

Put the following into the GotFocus property (the property - not
the event procedure) of every control whose caret should be hidden:
=HidePointer()

Put the same into the control's MouseUp property (the property -
not the event procedure) :
=HidePointer()

Keep in mind, I only did a cursory test (pun intended) of the
above. I did not do exhaustive testing, so as Peter suggests, it
may or may not work properly in Access.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

All,
I was wondering if there was a way of hiding the text select
cursor when a text box gets focus in Access 2007? Basically what
I'm looking for is to hide the blinking cursor when ever the
text box has focus.

I found two examples of calling the Windows API:

I was able to get the first one, which hides the mouse cursor
working...

Public Declare Function ShowCursor Lib "user32" (ByVal bShow As
Long) As Long


But unfortunately I think the one that will accomplish my task
"HideCaret"(???) doesn't seem to want to cooperate.

--- this is in a module ---

Public Declare Function HideCaret Lib "user32" (ByVal hwnd As
Long) As Long

Public Function ShowPointer()
Do While HideCaret(1) < 0
DoEvents
Loop
End Function

Public Function HidePointer()
Do While HideCaret(0) >= -1
DoEvents
Loop
End Function

--- this is in the form ---

Private Sub Text7_Enter()
Call HidePointer
End Sub


As I stated on not even sure if "HideCaret is the right API
Call? If anyone has a clue how to accomplish my goal I would
appreciate your advice. Thanks in advance. - CES

Graham,

Thank you for your help, it works as advertised with one caveat...
unfortunately the text box is the only element on the form that
has Tab Stop enabled. While the text box works properly after
you've done something on the form, such as move to the next
record, when it initially gets focus its still shows the Caret.

Is there a way of setting HidePointer when the form initially loads?

Also this is the first time that I've run into placing
=SomeFunction() in an event property and I'm not exactly sure what
the difference is between calling the function this way or

Private Sub control GotFocus()
Call SomeFunction
End Sub

It seems to me they both do the same thing? Thanks for your
guidance. - CES

Graham,
I'm not exactly sure what is meant when you say "call
SetFocus/GetFocus/HideCaret from within the form's Current event"
you mean

Private Sub Form_Current()
Me.Control.SetFocus
Me.Control.OnEnter = HidePointer() 'Has no effect... Doesn't this
just assign HidePointer() to the OnEnter event of the control??
etc.

Call HidePointer 'has no effect
Call Any sub Control_GotFocus() ' throws an error
End Sub

- CES

Graham,
thank you for getting back with me... unfortunately the problem is not
with my inexperience with VBS, this time.

I wanted to make sure that there wasn't some other code causing the
problem so I created a new access file to test out. You can find the
file at:

http://209.132.211.66/files/file.accdb

If you download the file you what find that I've done as suggested.
Unfortunately the problem persists when the form initaly loads... any
subsequent action on the form will indeed caused the caret to hide
properly but the action of initially displaying the form does not
produce the desired effect.

FYI - I've tried placing =HidePointer() in other Form Events
Form_Load(),Sub Form_Open, Form_GotFocus() besides Form_Current() but
they too do not hide the caret on the forms of initial open.

Re: calling =HidePointer() on a form event such as onCurrent - I'm not
exactly sure why doing this would cause the textbox to evoke the
method, because it doesn't receive focus until after the
Form_Current() Event has been executed? If I were to call the method
this way wouldn't that cause the caret to be hidden on form itself and
not any control?

Additionally I can't use =HidePointer() as you indicated because I
have other methods that need to be called in the Form_Current() Event
how would you call the method within a Sub routine.

Private Sub Form_Current()

Call HidePointer
Call OtherMethods

End Sub

In any event I really appreciate your time and effort, thank you - CES
Graham,
Not a problem...

My first question is what version of Access are you running??

Unfortunately there is no other code being executed. Did you have a chance to check out the file that I posted:

http://209.132.211.66/files/file.accdb

It's a blank database, opening a form that has one control on it that calls the method HidePointer(). Which gets us back to the first question. Unfortunately I know longer have access to an office 2003 version of MS Access, so I can test out my theory?

It's my belief the problem is not with the method HidePointer(), it's with Access itself. The reason I say that is because I have tried switching the control to a combo box and then calling me.name.dropdown and that to does not work.

- CES
 
Hello,

Did you try the workaround in my previous post? I paste it hear in case you
didn't see it

========

First I'd thanks Graham for sharing the knowledge of getting handle by
getfocus API.

CES, I think you may try to set time interval property of form to 1000, and
try to use following to hide cursor for the situation

Private Sub Form_Timer()
Call HidePointer

End Sub

Hope this is helpful.

======

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=====================================================
Please note that the newsgroups are staffed weekdays with a goal to provide
ONE BUSINESS DAY RESPONSE to all posts.

If this response time does not meet your needs, please contact CSS for more
immediate assistance:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;OfferProPhone#faq607
 
I was testing under Access 2007.

In Access 2007, put the following into the Detail section's OnPaint event
property:
=HidePointer()

In Access 2003, I think you might have to take up Peter's suggestion.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


CES said:
Graham said:
Hi again,

Again I apologise for not getting back to you sooner; I've been in the
bush for a week, with no access to the Internet.

I have checked and double checked, and calling =HidePointer() from [On
Got Focus] and [On Mouse Up] works for me every time without fail. It
should work for you also.

Given that you report it doesn't, I sugest that there is some code
running which steals focus control and then (behind the scenes) replaces
it. Check your form startup code step-by-step, visually checking the
controls' focus all the while. That will uncover the culprit.

After you know where the problem is, you can add a line of code to call
HidePointer().

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


CES said:
Graham R Seach wrote:
Sorry for not getting back to you earlier; I've been really busy.

It's hard to know people's level of expertise. I worked on the
assumption that you had enough knowledge to be able to follow what I
was saying. Not to worry. Let's start again.

1. Create a new module, and put the following at the top of it, below
where it says "Option Explicit". (If it doesn't say that at the top,
write it in).
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As Long)
As Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

2. Open your form in design view. Display the Properties dialog (View |
Properties). Select the Events tab.

3. Select the control whose caret you want to hide.

4. Where the Properties dialog says [On Got Focus], enter the following
text (including the = sign):
=HidePointer()

5. Do the same for [On Mouse Up].

6. Repeat Steps 3, 4 & 5 for each control whose caret you want to hide.

5. Select "Form" from the [Selection Type] in the Properties dialog.
Then enter the following into [On Curent]:
=HidePointer()

6. Save the form.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Graham R Seach wrote:
Placing a value in the event property is functionally the same as
writing a line of code within an event procedure, however, if you
want to call the same procedure (or macro) from several controls on
your form, it's far quicker than writing code for each procedure. For
example, in form design view, you can select several controls at
once, and enter a function name into the event property, and it will
automatically apply to *all* the controls you've selected. The
problem is (if you want to call it a problem) that the procedure name
you enter in the property MUST be a function - not a sub, and it must
be public, not private.

As for your remaining problem, I might suggest that you call
SetFocus/GetFocus/HideCaret from within the form's Current event.
That should take care of the initial caret visibility issue.

I still have to ask - why don't you like the caret? What did it ever
do to you? ;-)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Graham R Seach wrote:
Since Peter has teased you by indicating how you *might* be able to
do it, I'll continue his work by showing how you *can* do it.

The first thing you need to know is that what Peter said is half
right. Access controls are windowless until they have keyboard
focus. Since they are windowless, they don't have a hWnd property
as do VB controls. But, when they have the focus, you can use the
GetFocus() API to return its hWnd. Once you have the nWnd, you can
use HideCaret() API to, well, hide the caret.

The probem in your scenario is that two things can happen. If you
simply tab into the textbox, you can then call HideCaret(), and all
will work OK. But if you click into it, the GotFocus event will
fire and the caret will be terminated, but then the mouse events
will fire and undo all your good work. So I suggest calling
HideCaret() from both events.

Put the following into a standard module:
Public Declare Function GetFocus Lib "user32" () As Long
Public Declare Function HideCaret Lib "user32" (ByVal hWnd As
Long) As Long

Public Function HidePointer() As Boolean
Call HideCaret(GetFocus)
End Sub

Put the following into the GotFocus property (the property - not
the event procedure) of every control whose caret should be hidden:
=HidePointer()

Put the same into the control's MouseUp property (the property -
not the event procedure) :
=HidePointer()

Keep in mind, I only did a cursory test (pun intended) of the
above. I did not do exhaustive testing, so as Peter suggests, it
may or may not work properly in Access.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

All,
I was wondering if there was a way of hiding the text select
cursor when a text box gets focus in Access 2007? Basically what
I'm looking for is to hide the blinking cursor when ever the text
box has focus.

I found two examples of calling the Windows API:

I was able to get the first one, which hides the mouse cursor
working...

Public Declare Function ShowCursor Lib "user32" (ByVal bShow As
Long) As Long


But unfortunately I think the one that will accomplish my task
"HideCaret"(???) doesn't seem to want to cooperate.

--- this is in a module ---

Public Declare Function HideCaret Lib "user32" (ByVal hwnd As
Long) As Long

Public Function ShowPointer()
Do While HideCaret(1) < 0
DoEvents
Loop
End Function

Public Function HidePointer()
Do While HideCaret(0) >= -1
DoEvents
Loop
End Function

--- this is in the form ---

Private Sub Text7_Enter()
Call HidePointer
End Sub


As I stated on not even sure if "HideCaret is the right API Call?
If anyone has a clue how to accomplish my goal I would appreciate
your advice. Thanks in advance. - CES

Graham,

Thank you for your help, it works as advertised with one caveat...
unfortunately the text box is the only element on the form that has
Tab Stop enabled. While the text box works properly after you've
done something on the form, such as move to the next record, when it
initially gets focus its still shows the Caret.

Is there a way of setting HidePointer when the form initially loads?

Also this is the first time that I've run into placing
=SomeFunction() in an event property and I'm not exactly sure what
the difference is between calling the function this way or

Private Sub control GotFocus()
Call SomeFunction
End Sub

It seems to me they both do the same thing? Thanks for your
guidance. - CES

Graham,
I'm not exactly sure what is meant when you say "call
SetFocus/GetFocus/HideCaret from within the form's Current event" you
mean

Private Sub Form_Current()
Me.Control.SetFocus
Me.Control.OnEnter = HidePointer() 'Has no effect... Doesn't this just
assign HidePointer() to the OnEnter event of the control??
etc.

Call HidePointer 'has no effect
Call Any sub Control_GotFocus() ' throws an error
End Sub

- CES


Graham,
thank you for getting back with me... unfortunately the problem is not
with my inexperience with VBS, this time.

I wanted to make sure that there wasn't some other code causing the
problem so I created a new access file to test out. You can find the
file at:

http://209.132.211.66/files/file.accdb

If you download the file you what find that I've done as suggested.
Unfortunately the problem persists when the form initaly loads... any
subsequent action on the form will indeed caused the caret to hide
properly but the action of initially displaying the form does not
produce the desired effect.

FYI - I've tried placing =HidePointer() in other Form Events
Form_Load(),Sub Form_Open, Form_GotFocus() besides Form_Current() but
they too do not hide the caret on the forms of initial open.

Re: calling =HidePointer() on a form event such as onCurrent - I'm not
exactly sure why doing this would cause the textbox to evoke the method,
because it doesn't receive focus until after the Form_Current() Event
has been executed? If I were to call the method this way wouldn't that
cause the caret to be hidden on form itself and not any control?

Additionally I can't use =HidePointer() as you indicated because I have
other methods that need to be called in the Form_Current() Event how
would you call the method within a Sub routine.

Private Sub Form_Current()

Call HidePointer
Call OtherMethods

End Sub

In any event I really appreciate your time and effort, thank you - CES
Graham,
Not a problem...

My first question is what version of Access are you running??

Unfortunately there is no other code being executed. Did you have a chance
to check out the file that I posted:

http://209.132.211.66/files/file.accdb

It's a blank database, opening a form that has one control on it that
calls the method HidePointer(). Which gets us back to the first question.
Unfortunately I know longer have access to an office 2003 version of MS
Access, so I can test out my theory?

It's my belief the problem is not with the method HidePointer(), it's with
Access itself. The reason I say that is because I have tried switching the
control to a combo box and then calling me.name.dropdown and that to does
not work.

- CES
 
Back
Top