Validating the order & number of characters in an unbound text box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to ensure letters are entered in a particular order and to a finite number. Specifically roman numerals in the order MDCLXVI and in the number 7 M's 1D 4C's 1L 4X's 1 V & 4 I's.They only have to be additive, so allowing for subtraction like IX is not necessary for this particular application. If the only rule being applied is additive then 1999 becomes MDCCCCLXXXXVIIII rather than MCMXCIX. I can restrict the entry to only these letters OK I only need to restrict the order and number Is there any way of achieving this
..
 
Try something along the following lines in the textbox's
AfterUpdate eventhandler

Dim lngCStart As Long
Dim lngDStart As Long
Dim lngIStart As Long
Dim lngLStart As Long
Dim lngMStart As Long
Dim lngVStart As Long
Dim lngXStart As Long
Dim lngCCount As Long
Dim lngDCount As Long
Dim lngICount As Long
Dim lngLCount As Long
Dim lngMCount As Long
Dim lngVCount As Long
Dim lngXCount As Long
Dim lngSub As Long

lngCStart = 0
lngDStart = 0
lngIStart = 0
lngLStart = 0
lngMStart = 0
lngVStart = 0
lngXStart = 0
lngCCount = 0
lngDCount = 0
lngICount = 0
lngLCount = 0
lngMCount = 0
lngVCount = 0
lngXCount = 0

For lngSub = Len({yourTextBoxName}) To 1 Step -1
Select Case Mid({yourTextBoxName}, lngSub, 1)
Case "C"
lngCStart = lngSub
lngCCount = lngCCount + 1
Case "D"
lngDStart = lngSub
lngDCount = lngDCount + 1
Case "I"
lngIStart = lngSub
lngICount = lngICount + 1
Case "L"
lngLStart = lngSub
lngLCount = lngLCount + 1
Case "M"
lngMStart = lngSub
lngMCount = lngMCount + 1
Case "V"
lngVStart = lngSub
lngVCount = lngVCount + 1
Case "X"
lngXStart = lngSub
lngXCount = lngXCount + 1
Case Else
MsgBox "Invalid Character"
End Select
Next

If lngCCount > 4 Then
MsgBox "Invalid C Count"
End If
If lngDCount > 1 Then
MsgBox "Invalid D Count"
End If
If lngICount > 4 Then
MsgBox "Invalid I Count"
End If
If lngLCount > 1 Then
MsgBox "Invalid L Count"
End If
If lngMCount > 7 Then
MsgBox "Invalid M Count"
End If
If lngVCount > 1 Then
MsgBox "Invalid V Count"
End If
If lngXCount > 4 Then
MsgBox "Invalid X Count"
End If

If lngMStart > 1 Then
MsgBox "Invalid M Start"
End If

If lngDStart <> 0 And lngDStart <> lngMCount + 1 Then
MsgBox "Invalid D Start"
End If

If lngCStart <> 0 And lngCStart <> lngMCount + lngDCount +
1 Then
MsgBox "Invalid C Start"
End If

If lngLStart <> 0 And lngLStart <> lngMCount + lngDCount +
lngCCount + 1 Then
MsgBox "Invalid L Start"
End If

If lngXStart <> 0 And lngXStart <> lngMCount + lngDCount +
lngCCount + lngLStart + 1 Then
MsgBox "Invalid X Start"
End If

If lngVStart <> 0 And lngVStart <> lngMCount + lngDCount +
lngCCount + lngLStart + lngXStart + 1 Then
MsgBox "Invalid V Start"
End If

If lngIStart <> 0 And lngIStart <> lngMCount + lngDCount +
lngCCount + lngLStart + lngXStart + lngVStart + 1 Then
MsgBox "Invalid I Start"
End If

Replace {yourTextBoxName} with the name of your textbox
control. I have used Msgbox to highlight error conditions.
You may wish to put in your own error handling

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
I want to ensure letters are entered in a particular order
and to a finite number. Specifically roman numerals in the
order MDCLXVI and in the number 7 M's 1D 4C's 1L 4X's 1 V &
4 I's.They only have to be additive, so allowing for
subtraction like IX is not necessary for this particular
application. If the only rule being applied is additive
then 1999 becomes MDCCCCLXXXXVIIII rather than MCMXCIX. I
can restrict the entry to only these letters OK I only need
to restrict the order and number Is there any way of
achieving this?
 
See previous thread.

Please be patient. Since this is a volunteer service, replies within 24
hours are considered reasonable and you should only re-post the question
after a reasonable period of time. Please see:

http://www.mvps.org/access/netiquette.htm

--
HTH
Van T. Dinh
MVP (Access)


David said:
I want to ensure letters are entered in a particular order and to a finite
number. Specifically roman numerals in the order MDCLXVI and in the number 7
M's 1D 4C's 1L 4X's 1 V & 4 I's.They only have to be additive, so allowing
for subtraction like IX is not necessary for this particular application. If
the only rule being applied is additive then 1999 becomes MDCCCCLXXXXVIIII
rather than MCMXCIX. I can restrict the entry to only these letters OK I
only need to restrict the order and number Is there any way of achieving
this?
 
Back
Top