INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Cursor position - uncommitted data

Cursor position - uncommitted data

(OP)
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.

RE: Cursor position - uncommitted data

(OP)
For anyone who might be interested (looks like not manysmile - 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.

RE: Cursor position - uncommitted data

FYI:

ALT  CTRL   SHIFT

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


Get the idea?  smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close