Re: How to insert a '*' in certain controls when Enter is pressed.
- From: ThomasAJ <ThomasAJ@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 5 Jan 2008 18:10:00 -0800
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
- References:
- Re: How to insert a '*' in certain controls when Enter is pressed.
- From: Minton M
- Re: How to insert a '*' in certain controls when Enter is pressed.
- From: ThomasAJ
- Re: How to insert a '*' in certain controls when Enter is pressed.
- From: Allen Browne
- Re: How to insert a '*' in certain controls when Enter is pressed.
- From: ThomasAJ
- Re: How to insert a '*' in certain controls when Enter is pressed.
- From: Allen Browne
- Re: How to insert a '*' in certain controls when Enter is pressed.
- From: Marshall Barton
- Re: How to insert a '*' in certain controls when Enter is pressed.
- Prev by Date: Re: How to insert a '*' in certain controls when Enter is pressed.
- Next by Date: Re: Show last 'X' records in a subform
- Previous by thread: Re: How to insert a '*' in certain controls when Enter is pressed.
- Next by thread: Re: Problem with Data Types
- Index(es):
Relevant Pages
|