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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor position - uncommitted data

Status
Not open for further replies.

AKMonkeyboy

IS-IT--Management
Feb 4, 2002
141
US
I've got an insert statement that puts user comments into a field when they press say CTRL-0 - the problem is I can only get the data to append to the current data.

I modified the code to determine the cursor position and insert at that point, but this only works on data that has been committed to the database. Any thoughts on how to insert text into a field at the cursor position when the data is not committed?

Here's what I've got to this point:

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 2  'CTRL is down
        Select Case skc
              Case "0"
                If IsNull(Me.ActiveControl) = True Then
                    Me.ActiveControl = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=" & 0)
                Else
                    Me.ActiveControl.SelText = DLookup("[Comment]", "[TblDefaultComments]", "[ID]=0")
                End If              
              End Select
  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.
 
For anyone who might be interested (looks like not many:) - I found a solution to this problem. By defining a public variable, I was able to overcome the need to commit data before inserting a comment.

Here's what I ended up with - feel free to respond to this post if you've got any questions.

Code:
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 0 To 9
                    pstrReturnComment = Nz(DLookup("[Comment]", "[TblDefaultComments]", "[ID]=" & skc), "")
                    Me.ActiveControl.SelText = pstrReturnComment
                    pstrReturnComment = ""
                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.
 
FYI:

ALT CTRL SHIFT

1 1 1 = 7
0 1 1 = 3
1 1 0 = 6


Get the idea? :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top