Results 1 to 4 of 4

Thread: KeyPress & KeyDown

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118
    I am using the following code to update a field in a DB. The only problem is I have to hit the key twice for it to work.
    Code:
    Private Sub txtService_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyDelete Then
            UpdateNote
            
        End If
    End Sub
    Private Sub txtService_KeyPress(KeyAscii As Integer)
        If KeyAscii = 8 Then
        UpdateNote
        Else
            KeyAscii = 0
        End If
    End Sub
    Private Sub UpdateNote()
        Dim strSQL As String
        Dim oRS As Recordset
        Dim strName As String
        
             strName = txtCustName
             strSQL = "SELECT  ServiceNotes "
             strSQL = strSQL & "FROM Locations "
             strSQL = strSQL & "WHERE Location = '" & ListView1.SelectedItem & "' And Customer = '" & strName & "'"
             
             Set oRS = New Recordset
             oRS.Open strSQL, goConn, _
                     adOpenKeyset, adLockPessimistic, adCmdText
             
             With oRS
                 !ServiceNotes = Str2Field(txtService)
             End With
            oRS.Update
            oRS.Close
        
    End Sub
    How can I do this?
    Kokopeli
    VB6 SP3

  2. #2
    Guest
    Why do you have it in both events? Only one event is necessary.

    Choose whichever one you want, both work the same.
    Set the Form's KeyPreview property to True.
    And it should work.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Okay

    Now I have it in one event. I started with the keypress, but couldn't figure out the Delete in that, so went to keydown.
    Code:
    Private Sub txtService_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyDelete Or vbKeyBack Then
            UpdateNote
            End If
    End Sub
    but I still need to hit it twice. If I wanted Gatess to say Gates, I have to backspace to Gate. If I highlight and hit delete once, nothing happens. If I hit it twice, it works. Let me clear this up. The textbox is doing as it should, it is the saved field that is wrong. If I change it in the textbox to "Gate" it will come back as "Gates" the next time I go to that item in the listview.
    Kokopeli
    VB6 SP3

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Got it.

    Used KeyUp. That fixed it.
    Kokopeli
    VB6 SP3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width