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