wearytraveller
Programmer
Hello my again, In my MDI application I have several forms and many text boxes on each form. I have been wondering how to ensure that data entered into a text box is correctly formatted, here is my answer;
Private Sub txtContactName_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtContactName.Leave
Dim MyString As String
Dim TrimString As String
Dim newstring As String
'Check that data has been entered in ContactName field, if there is then,
'Remove any spaces at the start of the text string in txtContactName.text, then
'convert text in field to proper case ie STREET/street to Street...
If txtContactName.Text <> "" Then
MyString = txtContactName.Text
TrimString = LTrim(MyString)
txtContactName.Text = TrimString
newstring = StrConv(TrimString, VbStrConv.ProperCase)
txtContactName.Text = newstring
Else
'If there is no entry in this field show message...
Me.DialogResult = DialogResult.None
Beep()
StatusBar1.Text = "Mandatory Field: You must enter Contact Name"
'Set the focus to Address...
txtContactName.Focus()
End If
End Sub
This works well BUT I have had to write this for most of the text boxes can I use a module to do this and reduce the amount of code I have to write??
Private Sub txtContactName_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtContactName.Leave
Dim MyString As String
Dim TrimString As String
Dim newstring As String
'Check that data has been entered in ContactName field, if there is then,
'Remove any spaces at the start of the text string in txtContactName.text, then
'convert text in field to proper case ie STREET/street to Street...
If txtContactName.Text <> "" Then
MyString = txtContactName.Text
TrimString = LTrim(MyString)
txtContactName.Text = TrimString
newstring = StrConv(TrimString, VbStrConv.ProperCase)
txtContactName.Text = newstring
Else
'If there is no entry in this field show message...
Me.DialogResult = DialogResult.None
Beep()
StatusBar1.Text = "Mandatory Field: You must enter Contact Name"
'Set the focus to Address...
txtContactName.Focus()
End If
End Sub
This works well BUT I have had to write this for most of the text boxes can I use a module to do this and reduce the amount of code I have to write??