Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reusable Sub? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    I have the following 2 identicial sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reusable Sub? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    1) Create a procedure

    Private Sub Handle_Enter()
    Screen.ActiveControl.SelStart = Screen.ActiveControl.SelLength
    End Sub

    in the form module, and call it from the On Enter event of all of the controls:

    Private Sub Permit_Enter()
    Handle_Enter
    End Sub

    etc.

    2) Set the Key Preview property of the form to True, and handle the On KeyDown event there instead of for each individual control. So remove all the ..._KeyDown event procedures, and replace them with a single procedure

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    On Error GoTo ErrorHandler

    Select Case KeyCode
    Case vbKeyUp
    If fIsComboOpen = True Then
    Exit Sub
    End If
    RunCommand acCmdRecordsGoToPrevious
    KeyCode = 0
    Case vbKeyDown
    If fIsComboOpen = True Then
    Exit Sub
    End If
    '03/23/05 do not let the operator move down from a blank record
    If Not IsNull(Screen.ActiveControl) Then
    RunCommand acCmdRecordsGoToNext
    End If
    KeyCode = 0
    End Select

    ErrorHandler:
    Select Case Err.Number
    Case 2046
    'MsgBox "You can't go beyond current record(s)! " & " (" & Err.Number & ")"
    KeyCode = 0
    Case Else
    MsgBox "Error: " & Err.Description & " (" & Err.Number & ")"
    End Select
    End Sub

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reusable Sub? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Hi Hans

    I'm getting "Error" (0)" message moving using the key boaard moving field to field

    Any clues?

    Thanks, John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reusable Sub? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Sorry, I made a last minute change and didn't test it <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30>

    Immediately below End Select in the Handle_Keydown procedure, insert a line

    Exit Sub

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reusable Sub? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Thank you

Posting Permissions

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