Turn On Num Lock

D

Douglas J. Steele

Why do you want to? Personally, I think it's a very bad idea, since your
users may be using other applications concurrent with yours, and you could
cause them problems.

That being said, the code in http://www.mvps.org/access/api/api0046.htm at
"The Access Web" has a ToggleNumLock routine in it.
 
R

Ross

Sorry that I didn't get back sooner.

I have had this happen before on some but not all of my programs but, as
Karen is using a form with many filters to edit data, it OFTEN (but not
consistently or predictably) turns her num locks OFF. This is very
frustrating for her and I must either:

1. Determine why Access is turning off her numlock or
2. Force it to stay on with code.

I figured the second option would be easier but I have bun unable to find
the code.

I had this happen in 2000 for a program that I wrote in MS Access 97. I
found code worked perfectly but was quite complicated. As I recall, the code
had to identify the current operating system before it could turn the
numlocks ON or OFF.

Thanks

Ross
 
D

Dirk Goldgar

Ross said:
Sorry that I didn't get back sooner.

I have had this happen before on some but not all of my programs but, as
Karen is using a form with many filters to edit data, it OFTEN (but not
consistently or predictably) turns her num locks OFF. This is very
frustrating for her and I must either:

1. Determine why Access is turning off her numlock or
2. Force it to stay on with code.

I figured the second option would be easier but I have bun unable to find
the code.

I had this happen in 2000 for a program that I wrote in MS Access 97. I
found code worked perfectly but was quite complicated. As I recall, the
code
had to identify the current operating system before it could turn the
numlocks ON or OFF.


Are you using the SendKeys statement in your code? That has been known to
turn off NumLock:

http://www.mvps.org/access/bugs/bugs0004.htm
Bugs: Numlock key keeps turning off
 
R

Ross

Send Keys? Really, Well, you have just identified what is causing it.

Here is the code.

'******************************
Private Sub txtFLTAcct_Change()
'******************************
'Set the Filter Row source

cmdClose.SetFocus
txtFLTAcct.SetFocus
SendKeys "{F2}"

Set_List_Box_Rowsource_Filters

end sub

I want to evaluated the value of a field in a form before it is updated and
then run queries that filter and on the value of the field in the form before
it is updated.

If I type Abc, my filters read Like "Abc" & "*".

So to eliminate the about code: How do I evaluate the value of the field
after each keystroke and have the cursor remain an the end of the field in
the for after each entry (Hence:SendKeys "{F2}") sends the cursor to the end
of the field are re-enetering. I leave the to force the keystrokes to update.

Thanks Dirk.

Ross
 
D

Dirk Goldgar

Ross said:
Send Keys? Really, Well, you have just identified what is causing it.

Here is the code.

'******************************
Private Sub txtFLTAcct_Change()
'******************************
'Set the Filter Row source

cmdClose.SetFocus
txtFLTAcct.SetFocus
SendKeys "{F2}"

Set_List_Box_Rowsource_Filters

end sub

I want to evaluated the value of a field in a form before it is updated
and
then run queries that filter and on the value of the field in the form
before
it is updated.

If I type Abc, my filters read Like "Abc" & "*".

So to eliminate the about code: How do I evaluate the value of the field
after each keystroke and have the cursor remain an the end of the field in
the for after each entry (Hence:SendKeys "{F2}") sends the cursor to the
end
of the field are re-enetering. I leave the to force the keystrokes to
update.


If I understand what you're trying to do, you want to use the changing text
in the text box to adjust your filters, as the user is typing in the text
box. Because Access doesn't normally update the control's Value property
until the user leaves the control, you have this code in the Change event to
force the value to be updated by sending the focus to another control and
back again. The problem your SendKeys is intended to resolve is that, when
the focus comes back to the text box, the user's entry is automatically
selected, and you need to de-select the text and put the caret at the end of
it so the user's next keystroke doesn't overwrite the existing text.

Is that a correct statement of the situation?

If so, I can suggest a way to do this that relieves a lot of the trouble.
Instead of moving the focus around, use the Change event to set the Value of
the text box to the displayed text, like this:

'----- start of suggested code -----
'******************************
Private Sub txtFLTAcct_Change()
'******************************
'Set the Filter Row source

With Me.txtFLTAcct
If Len(.Text) > 0 Then
.Value = Null
Else
.Value = .Text
End If

Set_List_Box_Rowsource_Filters

End Sub

'----- end of suggested code -----

Try that and see if it works for you.
 
R

Ross

Dirk,

I have come a long way from where I started but:

I did get it.

Your code almost works

I have to change your code from:

With Me.txtFLTAcct
If Len(.Text) > 0 Then
.Value = Null
Else
.Value = .Text
End If


To This:

txtFLTAcct.SetFocus

With Me.txtFLTAcct
If Len(.Text) > 0 Then
.Value = .Text
Me.txtFLTAcct.SelStart = Len(.Text)
Else
.Value = Null
End If
End With

No more sendkeys!
No more num lock problems!

Thanks to All on this post

Ross
 
D

Dirk Goldgar

Ross said:
Dirk,

I have come a long way from where I started but:

I did get it.

Your code almost works

I have to change your code from:

With Me.txtFLTAcct
If Len(.Text) > 0 Then
.Value = Null
Else
.Value = .Text
End If


To This:

txtFLTAcct.SetFocus

With Me.txtFLTAcct
If Len(.Text) > 0 Then
.Value = .Text
Me.txtFLTAcct.SelStart = Len(.Text)
Else
.Value = Null
End If
End With

No more sendkeys!
No more num lock problems!


Great, Ross! I'm curious about one thing, though. Why did you have to set
the focus to txtFLTAcct? If this code was executing in the Change event of
txtFLTAcct, it seems to me that txtFLTAcct must have the focus.
 
R

Ross

Dirk,

I had to use the setfoce because the field refreshes "on Open" the form and
"cmdClear the form" and I got an error that "With Me.txtFLTAcct" can't run
without focus (which makes sense).

Thanks again. This is somewhat of a powerful methology for a keystroke by
keystroke filter change.

It even will do spaces like "United States" (space between d and S). With
my Sendkeys method you always loose the space which was another problem.

Thanks again.
 
D

Dirk Goldgar

Ross said:
Dirk,

I had to use the setfoce because the field refreshes "on Open" the form
and
"cmdClear the form"

I guess I see, but I don't know about what you're doing in those procedures.
There might have been a way to avoid using the SetFocus. Are you, then,
calling the txtFLTAcct_Change() procedure from these procedures?
and I got an error that "With Me.txtFLTAcct" can't run
without focus (which makes sense).

I don't think it would be the With statement, but rather the reference to
the .Text property.
Thanks again. This is somewhat of a powerful methology for a keystroke by
keystroke filter change.

Interestingly, yours was the second case in the same week where this
technique came up.

I think you could improve your code slightly -- assuming you really do need
to set the focus -- like this:

With Me.txtFLTAcct
.SetFocus
If Len(.Text) > 0 Then
.Value = .Text
.SelStart = Len(.Text)
Else
.Value = Null
End If
End With
 

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.

Ask a Question

Top