aarondewberry
IS-IT--Management
Hi all
Please look at the below code.
I use this on one of my forms to make sure that all text boxes are filled in before the form is allowed to be closed.
What i want to do next is:- On a different form i have a combo box, its called "cboStatus". When i select the field "Billed" from cboStatus then i don't want a user to be able to close the form until they fill in the Text boxes "txtname", "txtDate" & "txtcategory"
Note: There are other text boxes on this form and other fields in my "cboStatus" combo box. But I only want this code to work in this particular scenario.
Is this possible?
'Attribute VB_Name = "Module1"
'Option Compare Database
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 " & Ctl.Name & "," & vbCr & _
"please ensure this is entered.", _
vbInformation, "Required Data..."
RequiredData = True
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
Please look at the below code.
I use this on one of my forms to make sure that all text boxes are filled in before the form is allowed to be closed.
What i want to do next is:- On a different form i have a combo box, its called "cboStatus". When i select the field "Billed" from cboStatus then i don't want a user to be able to close the form until they fill in the Text boxes "txtname", "txtDate" & "txtcategory"
Note: There are other text boxes on this form and other fields in my "cboStatus" combo box. But I only want this code to work in this particular scenario.
Is this possible?
'Attribute VB_Name = "Module1"
'Option Compare Database
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 " & Ctl.Name & "," & vbCr & _
"please ensure this is entered.", _
vbInformation, "Required Data..."
RequiredData = True
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