How to check on a specific format of a string in Textbox

M

Marcel Stoop

Hi,

1) Is it possible to verify if the entered value in a textbox looks like,
(YYYY "text"): for instance "2005 the weather is fine".
I want to prevent that a user forgets to fill out a year

2) how do I check that a date which will be filled in a text box looks like:
YY/YY: for instance "04/05"
I want to prevent that a user fills out the date like: "04-05" or like
"2004/2005"

Thanks for the help

Marcel
 
K

Kai Apel \(Berlin\)

Did you know the Format-Function? Searching for in the Online-Help!

to 1) normaly i would prefer to seperate the year from the string, I don´t
know how you can manage this with the insertformat, but you can checkout if
the first 4 letters are the numeric: for example
something like that!

Private Sub txtBox_BeforeUpdate(Cancel As Integer)
Dim strYear As String
Dim strRest As String

'First checkout that your Textbox isn´t Zero
If IsNull(Me.txtBox) = True OR Me.txtBox = "" then
MsgBox "string is empty!"
Else
strYear = Left(Me.txtBox, 4)
strRest = Right(Me.txtBox, Len(Me.txtBox) - 4)
'to checkout, if the first 4 letters are numeric!
If IsNumeric(strYear) Then
MsgBox "Year: " & strYear & vbLf & "Rest: " & strRest
Else
MsgBox "No Year inside the string: " & Me.txtBox
Exit Sub
End If
End if
End Sub

So you have the possabilty to check out the year string


to 2) under the Register try ##"/"## for Insertformat for example

Kai Apel (Berlin)

PD:
 
Top