thurst
asked on
ASCII Key press problem
I am having a problem with some code I have. On my main search screen I have setup code to copy specific data to the clip board on certain ASCII key presses. This works fine if the listview item has focus (ie. Blue) but if I open a record and come back to it the listview item is ghosted. If the user does not click on the item and presses one of my defined buttons I get a runtime 91 error as it is not the "ActiveControl".
If I put a "On Error Resume Next" under the Clipboard.Clear then it stops the error but doesn't cycle throught the code correctly. eg If you press the A key it cycles throught the U code then exits.
How can I remedy this without simply telling the user to highlight the record before using these keys.
Original code below:
-----
Private Sub Form_KeyPress(KeyAscii As Integer)
Clipboard.Clear
If Screen.ActiveControl.Name = "lvwSearch" And (KeyAscii = 117 Or KeyAscii = 85) Then
Clipboard.SetText (Me.lvwSearch.SelectedItem .SubItems( 7)) 'UMRN (U, u)
ElseIf Screen.ActiveControl.Name = "lvwSearch" And (KeyAscii = 97 Or KeyAscii = 65) Then
Clipboard.SetText (Me.lvwSearch.SelectedItem .SubItems( 3)) 'ACC NBR (A, a)
ElseIf Screen.ActiveControl.Name = "lvwSearch" And (KeyAscii = 80 Or KeyAscii = 112) Then
Clipboard.SetText (Me.lvwSearch.SelectedItem .SubItems( 13)) 'Patient ID (P,p)
ElseIf Screen.ActiveControl.Name = "lvwSearch" And (KeyAscii = 88 Or KeyAscii = 120) Then
If Me.lvwSearch.SelectedItem. SubItems(1 4) <> "" Then
Clipboard.SetText "intpatdetid = " & (Me.lvwSearch.SelectedItem .SubItems( 14)) 'PatDetID (X,x)
ElseIf Me.lvwSearch.SelectedItem. SubItems(1 5) <> "" Then
Clipboard.SetText "intreferralid = " & (Me.lvwSearch.SelectedItem .SubItems( 15)) 'ReferralID (X,x)
Else
Clipboard.SetText "INTEMERGID = " & (Me.lvwSearch.SelectedItem .SubItems( 16)) 'EmergID (X,x)
End If
End If
If KeyAscii = vbKeyReturn Then
SendKeys "{Tab}"
KeyAscii = 0
End If
End Sub
If I put a "On Error Resume Next" under the Clipboard.Clear then it stops the error but doesn't cycle throught the code correctly. eg If you press the A key it cycles throught the U code then exits.
How can I remedy this without simply telling the user to highlight the record before using these keys.
Original code below:
-----
Private Sub Form_KeyPress(KeyAscii As Integer)
Clipboard.Clear
If Screen.ActiveControl.Name = "lvwSearch" And (KeyAscii = 117 Or KeyAscii = 85) Then
Clipboard.SetText (Me.lvwSearch.SelectedItem
ElseIf Screen.ActiveControl.Name = "lvwSearch" And (KeyAscii = 97 Or KeyAscii = 65) Then
Clipboard.SetText (Me.lvwSearch.SelectedItem
ElseIf Screen.ActiveControl.Name = "lvwSearch" And (KeyAscii = 80 Or KeyAscii = 112) Then
Clipboard.SetText (Me.lvwSearch.SelectedItem
ElseIf Screen.ActiveControl.Name = "lvwSearch" And (KeyAscii = 88 Or KeyAscii = 120) Then
If Me.lvwSearch.SelectedItem.
Clipboard.SetText "intpatdetid = " & (Me.lvwSearch.SelectedItem
ElseIf Me.lvwSearch.SelectedItem.
Clipboard.SetText "intreferralid = " & (Me.lvwSearch.SelectedItem
Else
Clipboard.SetText "INTEMERGID = " & (Me.lvwSearch.SelectedItem
End If
End If
If KeyAscii = vbKeyReturn Then
SendKeys "{Tab}"
KeyAscii = 0
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
-->Accept robertlees's comment as Answer
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER
GPrentice00
Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
-->Accept robertlees's comment as Answer
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER
GPrentice00
Cleanup Volunteer
This old question (QID 20563203) needs to be finalized -- accept an answer, split points, or get a refund. Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.