SendKeys

H

Hardhit

Hello,

I have a form in my scoring database where I use SendKeys to fill the form
with scores ranging from 0 to 10.
In order not to enter the score and having to press enter I use the send key
where I hold the control key and then use the number 0 - 9 to send the
corresponding score.
when I send ctrl-0 I in fact enter the score of 10 points.
when I send ctrl-o I in fact enter the score of 0 points in the form.
After each entry with the SendKeys the cursor is moved to the next field.
I would like to get ride of the SendKeys macro to send the numbers and also
not to use the CTRL key anymore.
So what I would like to do is enter 0 ... 9 to send a score of 0 ... 9 into
the field and when the score is a 10 I would like to use *
How would I go about this in VB ?
I'm not that used to VB.

Regards,
Peter
 
J

John Spencer

Are there any other controls on the form that should be getting data? Or is
there only one control that you want to fill.


--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
H

Hardhit

Hello John,

On the form are 60 controls which depending on the match receive a score.
So it can be that only 10, 20, 30, .., 60 controls (fields) need to be
filled.

Regards,
Peter
 
J

John Spencer

Ok, I'm a bit suspicious of your data structure since you seem to have 60
controls that store the same type of information. The following MIGHT work
for you

Hopefully, you've named the controls with some naming scheme like
Score01, Score02, ..., Score59, Score60

If so, you could create a function on the form like the following UNTESTED
one.
After you have created the function, select All the Score controls (shift
Click, drag around them all) and on the property sheet event type
=fSetValueAndMove()
into the KeyPress event.

Public Function fSetValueAndMove(ByRef KeyAscii as Integer)
'UNTESTED AIR CODE
Dim ctl As Control
Dim strCtlName As String
Dim iCtlNum As Long

Set ctl = Screen.ActiveControl
strCtlName = ctl.Name
iCtlNum = Val(Right(strCtlName, 2)) + 1

strCtlName = Left(strCtlName, Len(strCtlName) - 2) & _
Format(iCtlNum, "00")

Select Case KeyAscii
Case 42
ctl = 100
Case 48 To 57 '0 to 9 multiply value by 10
ctl = (KeyAscii - 48) * 10
Case Else
' ctl = Null
End Select

KeyAscii = 0 'eliminate key stroke

'Assuming the last control is numbered 60
If iCtlNum < 60 Then
Me.Controls(strCtlName).SetFocus
Else
'Comment the following line out if you want to stay on the last control
' change the TheNextControlName to the name of the next control on your
' form
Me.TheNextControlName.SetFocus
End If
End Sub

--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

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