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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form required field entry validation problem.

Status
Not open for further replies.

LD1010

Technical User
Dec 6, 2001
78
0
0
US
Thank you for reading my post.
I am using code provided by TheAceMan1 to perform required field entry validation. It works as expected for the main form and the 1st nested sub form, but does not seem to work on either the 2nd or subsequent nested sub forms.

I am tracking Customers, their contracts with us and each of the services that make up each contract. The form structure I'm using is a main form with nested sub forms.

Main form - "frmCustomerResEnter" - RS is "tblCustomers", Pk "CustomerID"

1st Sub Form - "sfrmContracts" - RS is "tblContracts", Pk "ContractID", Fk "CustomerID"

2nd Sub Form - "sfrmServiceItems" - RS is "tblServiceItems", Pk "ServiceItemID", Fk's "ContractID" and "ServiceTypeItemID"

3rd Sub Form - "sfrmHavcItems" - RS is tblHvacItems, Pk "HavcItemID", Fk "ServiceTypeItemID" (a composite key of "ServiceItemID" & "SerivceTypeID")
(There are 7 of the above sub forms, each for a different type of service. Each becomes visible based on the value entered in "cboServiceItemID" of "sfrmServiceItems")
I have put a question mark ? in Tag property of each of the required fields on each of the forms and placed the following code in the Before Update event of each of those forms.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

   Dim Msg As String, Style As Integer, Title As String
   Dim DL As String, ctl As Control
   
   DL = vbNewLine & vbNewLine
   
   For Each ctl In Me.Controls
      If ctl.Tag = "?" Then
         If Trim(ctl & "") = "" Then
            Msg = ctl.Name & " Is a Required Field!" & DL & _
                 "Please complete this field in order to continue . . ."
            Style = vbCritical + vbOKOnly
            Title = "Required Data Error"
            
            MsgBox Msg, Style, Title
            ctl.SetFocus
            Cancel = True
            Exit For
         End If
      End If
   Next
   
Exit_Form_BeforeUpdate:
    Exit Sub

Err_Form_BeforeUpdate:
    MsgBox Err.Description
    Resume Exit_Form_BeforeUpdate

End Sub
Can anyone provide any insight as to why it would not work it the 2nd and subsequent sub forms? Any help would be much appreciated.

 
The only thought I have is that you have not put this code on Each subform's before_update event.... I guess it could also be true that the tag properties are not set as you expect. Perhaps you have "? " or something instead of "?" for your tag properties.

 
does not seem to work on either the 2nd or subsequent nested sub forms

What IS it doing?
Have you tried putting a break in the code and stepping through to see exactly what's happening?


Randy
 
Thanks Lameid and Randy700 for responding to my post. Sorry to be so long getting back but I've was fighting a flue bug. The bug won.

Lameid, I had dubble checked that the "?_" did not have a trailing spaces and that each of the forms did in fact have the code in the BeforeUpdate event.

Randy700, sorry about the vagness of my post. What was NOT happening was that when I would cycle to a new record in any of 2nd and subsequent sub forms, and I had made no entry in the required fields, the code would not fire warning me that data entry was required.

It finally dawned on me what the problem was. In each forms all of the required fields were combo boxes which saved an ID number. When I looked back at my table structure I realized that I had a default value of 0 (zero) in each fields of each tables. Deleting the default 0 value solved the problem.

Thanks to both of you for your sugestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top