Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enter detail in txt box before close form!!!

Status
Not open for further replies.

aarondewberry

IS-IT--Management
Jul 20, 2005
148
GB
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
 
Just examine the value of the combo box and if it is "Billed" check for blanks or nulls in the other three text boxes. Surely this is an easier case because you know which boxes to test - or am I missing something?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top