Tech Eval
- From: "Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 13 Oct 2005 19:54:42 -0400
Hi,
I have a textbox in a userform that I am trying to limit the entries (real
time) to to characters allowed in a bookmark name (e.g., alpha characters,
numbers, "_"). The first character must me a letter and the maximum length
is 40 characters. I am also replacing spacebar entris (after the first
character) with "_".
The code below seems to be working but I was wondering if there was a way to
abbreviate "Me.TextBox1.Text" in some way and as I built this on the fly I
suspect that I have driven a tack with a ten pound hammer and have
overlooked a more graceful way of achieving the desired result.
Any ideas for improvement are appreciated.
Private Sub TextBox1_Change()
testChar = Right(Me.TextBox1.Text, 1)
If Len(Me.TextBox1.Text) = 1 Then
If InStr(" 0123456789", testChar) > 0 Then
Me.TextBox1.Text = Left(Me.TextBox1.Text, Len(Me.TextBox1.Text) - 1)
MsgBox "Bookmark name must begin with a" _
& " letter.", vbInformation & vbOKOnly, "Invalid Character"
End If
End If
On Error Resume Next
If InStr(Chr$(32), testChar) > 0 Then
Me.TextBox1.Text = Left(Me.TextBox1.Text, Len(Me.TextBox1.Text) - 1) _
& Chr$(95)
End If
On Error GoTo 0
On Error Resume Next
If InStr(Chr$(44) & " `~!@#$%^&*()-+={}[]|?/><:;""", testChar) > 0 Then
Me.TextBox1.Text = Left(Me.TextBox1.Text, Len(Me.TextBox1.Text) - 1)
End If
On Error GoTo 0
If Len(Me.TextBox1.Text) > 40 Then
MsgBox "Bookmark name is limited to 40 characters.", _
vbInformation & vbOKOnly, "Limit"
Me.TextBox1.Text = Left(Me.TextBox1.Text, 40)
End If
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
.
- Follow-Ups:
- Re: Tech Eval
- From: Tony Jollans
- Re: Tech Eval
- From: Jean-Guy Marcil
- Re: Tech Eval
- From: Jay Freedman
- Re: Tech Eval
- From: Shell
- Re: Tech Eval
- Prev by Date: Re: Help! Object Variable or With Block variable not set
- Next by Date: Re: Tech Eval
- Previous by thread: Help! Object Variable or With Block variable not set
- Next by thread: Re: Tech Eval
- Index(es):
Relevant Pages
|