AKMonkeyboy
IS-IT--Management
I've worked out some code (with the help of Tek-Tips experts, of course!) that will insert predefined statements into a users active field. Basically the user presses "CTRL" and a corresponding number to import text to a text box. This has worked well enough, but I would like to make it more user friendly by having the imported text placed at the current cursor position - the code that I have only puts the imported text at the end of the line.
Any thoughts on how to put imported text at the cursor instead?
Here's what I have so far:
Give a man a fish, and you feed him for a day.
Teach a man to fish, and you feed
him for life.
Send a man to Tek-Tips and the poor sap can find out how to fish on his own, and learn more by doing it.
Any thoughts on how to put imported text at the cursor instead?
Here's what I have so far:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_Form_KeyDown
Dim skc: skc = Chr(KeyCode)
Select Case Shift
'Case 0 'no modifier keys
'Case 1 'Shift is down
Case 2 'CTRL is down
Select Case skc
Case "i"
Me.ActiveControl.FontSize = Me.ActiveControl.FontSize + 1
Case "d"
Me.ActiveControl.FontSize = Me.ActiveControl.FontSize - 1
Case "0"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=0")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=0")
End If
Case "1"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=1")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=1")
End If
Case "2"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=2")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=2")
End If
Case "3"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=3")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=3")
End If
Case "4"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=4")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=4")
End If
Case "5"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=5")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=5")
End If
Case "6"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=6")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=6")
End If
Case "7"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=7")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=7")
End If
Case "8"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=8")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=8")
End If
Case "9"
Me.Refresh
If IsNull(Me.ActiveControl) = True Then
Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=9")
Else
Me.ActiveControl = Me.ActiveControl & " " & DLookup("[Comment]", "[TblDefaultComments]", "[ID]=9")
End If
End Select
'Case 3 'CTRL-SHIFT is down
'txtKey.Text = "You pressed CTRL-SHIFT-" & skc
'Case 4 'ALT is down
'Case 5 'SHIFT-ALT is down
'txtKey.Text = "You pressed SHIFT-ALT-" & skc
'Case 6 'CTRL-ALT is down
'txtKey.Text = "You pressed CTRL-ALT-" & skc
'Case 7 'CTRL-ALT-SHIFT is down
'txtKey.Text = "You pressed CTRL-ALT-SHIFT-" & skc
'Case Else
'txtKey.Text = "huh? SHIFT=" & Shift & " KEYCODE=" & KeyCode
End Select
Exit_Form_KeyDown:
Exit Sub
Err_Form_KeyDown:
MsgBox Err.Description
Resume Exit_Form_KeyDown
End Sub
Give a man a fish, and you feed him for a day.
Teach a man to fish, and you feed
him for life.
Send a man to Tek-Tips and the poor sap can find out how to fish on his own, and learn more by doing it.