LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Text Box Question

(snip rest of thread -it's about an autocomplete Forms2 textbox)
"Rich Cooper" skrev i melding
...
Coud i ask for your help to getting the backspace key to work. I would
appreciate that.


Ok. I never did this in VBA before, but I believe this is pretty close.
Complete code:

Option Explicit

Dim blnAuto As Boolean

Private Sub TextBox1_KeyDown(ByVal KeyCode As _
MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 8 'Backspace
TextBox1.SelText = ""
If TextBox1.SelStart 0 Then _
TextBox1.SelStart = TextBox1.SelStart - 1
TextBox1.SelLength = Len(TextBox1.Text) - TextBox1.SelStart
Case Else
End Select
End Sub

Private Sub TextBox1_Change()
Dim L As Long
Dim S As String
Dim Found As Range
If blnAuto = True Then Exit Sub
S = TextBox1.Text
On Error Resume Next
Set Found = _
Sheet1.Range("A1:A1000").Find(What:=S & "*", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Found Is Nothing Then
'write on
ElseIf TextBox1.SelStart = 0 Then
TextBox1.Text = ""
Else
blnAuto = True
L = Len(TextBox1.Text)
TextBox1.Text = Found.Value
TextBox1.SelStart = L
TextBox1.SelLength = Len(TextBox1.Text)
blnAuto = False
End If
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Select Case KeyCode
Case 8 'Backspace
TextBox1.SelText = ""
If TextBox1.SelStart 0 Then _
TextBox1.SelStart = TextBox1.SelStart - 1
TextBox1.SelLength = Len(TextBox1.Text) - TextBox1.SelStart
Case Else
End Select
End Sub

HTH. Best wishes Harald


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two question on working with text Marsh Excel Worksheet Functions 2 January 22nd 10 11:33 PM
Text to columns question Heidi Excel Worksheet Functions 5 January 27th 09 09:07 PM
Text to Columns Question Mark W. Excel Discussion (Misc queries) 1 April 15th 08 12:13 AM
Text box question Greg B... Excel Discussion (Misc queries) 0 March 1st 05 07:28 AM
Text box question Greg B... Excel Discussion (Misc queries) 3 February 27th 05 02:47 PM


All times are GMT +1. The time now is 04:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"