Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASCII Key press problem

Posted on 2003-03-25
3
Medium Priority
?
748 Views
Last Modified: 2008-02-01
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(14) <> "" Then
            Clipboard.SetText "intpatdetid = " & (Me.lvwSearch.SelectedItem.SubItems(14)) 'PatDetID (X,x)
        ElseIf Me.lvwSearch.SelectedItem.SubItems(15) <> "" 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



0
Comment
Question by:thurst
3 Comments
 
LVL 1

Accepted Solution

by:
robertlees earned 80 total points
ID: 8207757
The listview item is ghosted because the control doesn't have the focus, but you have set the HideSelection to True.

By testing Screen.ActiveControl.Name you are assuming it will have the focus.

Firstly why not try lvwSearch.SetFocus during Form_Activate - ie, when the form gets activated again after returning from another form, you give focus back to lvwSearch.

Alternatively, can you just test that a selection has been made, without requiring that it have the focus. That is, replace all your If Screen.ActiveControl.Name = "lvwSearch" tests with If Not (lvwSearch.SelectedItem Is Nothing)

0
 

Expert Comment

by:CleanupPing
ID: 8531595
Hi thurst,
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.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9441032
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question