lhardee
05-05-2008, 05:51 PM
Hello All,
I've created a textbox where I can control the user's entries whereby the first entry is automatically an "S" upon entering the textbox. The following entries are numerical values only.
See code below:
I know there is a better way to code this. Maybe a Case where the 1st entry is only an "S" and the following entries are numerical.
In short, I would like to get a better understanding of how to control what value can be entered for each entry.
Private Sub Segment_Enter()
Me.Segment.BackStyle = fmBackStyleOpaque
Me.Segment.Text = "S"
Me.Segment.SelStart = 1
Me.Segment.SetFocus
End Sub
Private Sub Segment_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc("-")
If InStr(1, Me.Segment.Text, "-") > 0 Or Me.Segment.SelStart > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, Me.Segment.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub
Thanks
lhardee
I've created a textbox where I can control the user's entries whereby the first entry is automatically an "S" upon entering the textbox. The following entries are numerical values only.
See code below:
I know there is a better way to code this. Maybe a Case where the 1st entry is only an "S" and the following entries are numerical.
In short, I would like to get a better understanding of how to control what value can be entered for each entry.
Private Sub Segment_Enter()
Me.Segment.BackStyle = fmBackStyleOpaque
Me.Segment.Text = "S"
Me.Segment.SelStart = 1
Me.Segment.SetFocus
End Sub
Private Sub Segment_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc("-")
If InStr(1, Me.Segment.Text, "-") > 0 Or Me.Segment.SelStart > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, Me.Segment.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub
Thanks
lhardee