if u didnt want to change it from text to number, I can see why considering you use - then here is sample code that validates the entry, changes to format expected
So u have text0
Private Sub Text0_BeforeUpdate(Cancel As Integer)
'ensure its in right format
Dim sLeft As String
Dim sRight As String
Dim sNewVal As String
Dim i As Integer
If Trim$(Nz(Text0.Value, "")) = "" Then
MsgBox "You must enter a value"
Cancel = True
Else
'check - entered, if not add one in
i = InStr(Text0.Value, "-")
If i = 0 Then
If Not IsNumeric(Text0.Value) Then
MsgBox "Only numerics allowed"
Cancel = True
Else
If Len(Text0.Value) > 2 Then
sNewVal = Val(Left$(Text0.Value, Len(Text0.Value) - 2)) & "-" & Right$(Text0.Value, 2)
Else
sNewVal = "0-" & Format(Text0.Value, "00")
End If
End If
i = InStr(sNewVal, "-")
Else
sNewVal = Text0.Value
End If
If Left$(sNewVal, "1") <> "-" Then
sLeft = Left$(sNewVal, i - 1)
Else
sLeft = "0"
End If
sRight = Mid$(sNewVal, i + 1)
If Not IsNumeric(sLeft) Then
MsgBox "Numeric required"
Cancel = True
ElseIf Not IsNumeric(sRight) Then
MsgBox "Numeric required"
Cancel = True
ElseIf Len(sRight) > 2 Then
MsgBox "Only 2 numbers allowed after -"
Cancel = True
ElseIf Len(sLeft) > 7 Then
MsgBox "Only 7 numbers allowed before -"
Cancel = True
Else
sNewVal = Val(sLeft) & "-" & Format(sRight, "00")
End If
End If
'set the new value on the tag property so that the afterupdate method can pick it up
Text0.Tag = sNewVal
End Sub
Private Sub Text0_AfterUpdate()
If Text0.Tag <> "" Then
Text0.Value = Text0.Tag
Text0.Tag = ""
End If
End Sub