Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keypress for all controls

Status
Not open for further replies.

uguimess

Technical User
Jul 29, 2009
24
CA
I have a subform for data entry with just textboxes on it. It displays in datasheet view.

I would like to have the onkeydown event for all textboxes on the form call a procedure.

But the user has the ability to run a procedure to add fields to the underlying table and add corresponding fields to the subform. So I need a way to get the newly generated field to also 'inherit' the onkeypress event.

The following (red) proc call is currently associated with one textbox. How can I make this proc available to the as yet non-existent fields upon their creation by the user?
Code:
Private Sub Text50_KeyDown(KeyCode As Integer, Shift As Integer)
    [COLOR=#ff0000]Call dfltCursorDirection(KeyCode, Shift)[/color]
End Sub

Public Sub dfltCursorDirection(KeyCode As Integer, Shift As Integer)

    If Me.Parent.Parent!grpCursorDirection = 2 Then
        'User has chosen to have cursur move
        'up and down when hitting Tab and Enter, so...
                                            
        On Error Resume Next
        With Me.Recordset
          Select Case KeyCode
          Case vbKeyTab, vbKeyReturn
            Select Case Shift
            Case 0
              .MoveNext
              If .EOF Then
    '            .MoveFirst
              End If
            Case acShiftMask
              .MovePrevious
              If .BOF Then
    '            .MoveLast
              End If
            Case Else
              'ignore
            End Select
          Case Else
            'Ignore
          End Select
        End With
    End If

End Sub


-------------------------------------
Where would we be if we didn't try?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top