T
Trev
Hi All
I need to validate that data is entered into three of 12
text boxes on a form and have no idea about writing code.
I looked at using the inbuilt data validation
capabilities of access but the database is used by a
number of users and my users found the standard message a
little confusing.
I found some great code from the net that will check that
data is entered in all text boxes but we don't need to
have data in all.
Assuming my text boxes as TextBox1, TextBox2 & Textbox3
Can I modify the code below to make it work for me or is
there a better way.
Public Function RequiredData(ByVal TheForm As Form) As
Boolean
'Check that all TextBox controls have required data
entered
Dim Ctl As Control
Dim Num As Integer
On Error GoTo Err_RequiredData
RequiredData = False
Num = 0
For Each Ctl In TheForm
If Ctl.ControlType = acTextBox Then
If Ctl = "" Or IsNull(Ctl) Then
Num = 1
Exit For
End If
End If
Next Ctl
If Num = 1 Then
MsgBox "Data is required in the " & Ctl.Name & "
field," & vbCr & _
"please ensure this is entered.", _
vbInformation, "Required Data..."
RequiredData = True
Ctl.SetFocus
Else
RequiredData = False
End If
Exit_RequiredData:
On Error Resume Next
If Not (Ctl Is Nothing) Then
Set Ctl = Nothing
End If
Exit Function
Err_RequiredData:
Select Case Err
Case 0
Resume Next
Case Else
MsgBox "Error: " & Err.Number & vbCrLf &
vbCrLf & Err.Description, _
VbInformation
End Select
End Function
Any help appreciated
Regards
I need to validate that data is entered into three of 12
text boxes on a form and have no idea about writing code.
I looked at using the inbuilt data validation
capabilities of access but the database is used by a
number of users and my users found the standard message a
little confusing.
I found some great code from the net that will check that
data is entered in all text boxes but we don't need to
have data in all.
Assuming my text boxes as TextBox1, TextBox2 & Textbox3
Can I modify the code below to make it work for me or is
there a better way.
Public Function RequiredData(ByVal TheForm As Form) As
Boolean
'Check that all TextBox controls have required data
entered
Dim Ctl As Control
Dim Num As Integer
On Error GoTo Err_RequiredData
RequiredData = False
Num = 0
For Each Ctl In TheForm
If Ctl.ControlType = acTextBox Then
If Ctl = "" Or IsNull(Ctl) Then
Num = 1
Exit For
End If
End If
Next Ctl
If Num = 1 Then
MsgBox "Data is required in the " & Ctl.Name & "
field," & vbCr & _
"please ensure this is entered.", _
vbInformation, "Required Data..."
RequiredData = True
Ctl.SetFocus
Else
RequiredData = False
End If
Exit_RequiredData:
On Error Resume Next
If Not (Ctl Is Nothing) Then
Set Ctl = Nothing
End If
Exit Function
Err_RequiredData:
Select Case Err
Case 0
Resume Next
Case Else
MsgBox "Error: " & Err.Number & vbCrLf &
vbCrLf & Err.Description, _
VbInformation
End Select
End Function
Any help appreciated
Regards