Re: How to insert a '*' in certain controls when Enter is pressed.



Thank you very very much. I really appreciate the effort. Thanks.
But ideally I do want to insert '* ' and the space disappears.

--
Regards
Tom


"Marshall Barton" wrote:

Allen, I think you can get the same effect using the SelText
property:

Private Sub Text0_KeyDown(KeyCode As Integer, Shift As
Integer)
Dim lngCursor As Long

If (KeyCode = vbKeyReturn) And (Shift = 0) Then
With Me.Text0
lngCursor = .SelStart
.SelText = vbCrLf & "*"
.SelStart = lngCursor + 3
End With
KeyCode = 0
End If
End Sub
--
Marsh
MVP [MS Access]


Allen Browne wrote:

Paste the function below into a module.

Then call it like this from sample text box named Text0:

Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
Call StarEnter(Me.Text0, KeyCode, Shift)
End Sub

Function StarEnter(ctl As Control, KeyCode As Integer, Shift As Integer)
'Purpose: Replace Enter keystroke with CrLf and asterisk.
Dim strPrior As String 'Text before the cursor.
Dim strAfter As String 'Text after the cursor.
Dim lngLen As Long 'Number of characters
Dim iSelStart As Integer 'Where cursor is.

'Ignore keystrokes other than Enter; ignore if Shift, Alt or Ctrl
pressed.
If (KeyCode = 13) And (Shift = 0) Then
With ctl
lngLen = Len(.Text)
'SelStart can't cope with more than 32k characters.
If lngLen <= 32764 Then
'Remember characters before cursor.
iSelStart = .SelStart
If iSelStart > 1 Then
strPrior = Left$(.Text, iSelStart)
End If
'Remember characters after selection.
If iSelStart + .SelLength < lngLen Then
strAfter = Mid$(.Text, iSelStart + .SelLength + 1)
End If
'Destroy the keystroke.
KeyCode = 0
'Assign prior characters, star, enter, and later characters.
.Text = strPrior & vbCrLf & "*" & strAfter
'Put the cursor back where it as, after the CR, LF, and *.
.SelStart = iSelStart + 3
End If
End With
End If
End Function


.



Relevant Pages

  • Re: How to insert a * in certain controls when Enter is pressed.
    ... Function StarEnter(ctl As Control, KeyCode As Integer, Shift As Integer) ... Dim strPrior As String 'Text before the cursor. ... Dim iSelStart As Integer 'Where cursor is. ... 'SelStart can't cope with more than 32k characters. ...
    (microsoft.public.access.formscoding)
  • Re: How to insert a * in certain controls when Enter is pressed.
    ... Function StarEnter(ctl As Control, KeyCode As Integer, Shift As Integer) ... Dim strPrior As String 'Text before the cursor. ... Dim iSelStart As Integer 'Where cursor is. ... 'SelStart can't cope with more than 32k characters. ...
    (microsoft.public.access.formscoding)
  • Re: How to insert a * in certain controls when Enter is pressed.
    ... 'Assign prior characters, star, enter, and later characters. ... 'Put the cursor back where it as, after the CR, LF, and *. ... Function StarEnter(ctl As Control, KeyCode As Integer, Shift As Integer) ... Dim iSelStart As Integer 'Where cursor is. ...
    (microsoft.public.access.formscoding)
  • Re: How to insert a * in certain controls when Enter is pressed.
    ... Function StarEnter(ctl As Control, KeyCode As Integer, Shift As Integer) ... Dim strPrior As String 'Text before the cursor. ... Dim iSelStart As Integer 'Where cursor is. ... 'SelStart can't cope with more than 32k characters. ...
    (microsoft.public.access.formscoding)
  • Re: Does anyone know how to do this
    ... characters which moves the paper...and so on and so forth... ... "cursor left" character would be a "carriage return" that just doesn't ... it _will_ work without needing "DirectX" and OS layers and device ... Graphics workstation that would print up control characters using ...
    (alt.lang.asm)