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

Conditional Required Fields

Status
Not open for further replies.

dannyocean

Technical User
Jan 26, 2001
136
US
Hi all,

I have a an entry form in my db. I am needing help to make fields required based upon previous data entry.

ex - If the product is Medicare then I need to make sure that they fill out the Critieria met field and then if this is false then I need to require the Criteria Not Met Letter Feild.

TIA,

Danny
 
You could try something like this:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.field1 = "Criteria" Then
        If Trim(Nz(Me.field2)) = "" Then
            MsgBox "Field2 is required when Field1 = Criteria"
            Cancel = True
            Me.field2.SetFocus
        End If
    End If
End Sub
 
Where exactly would I put this. Would I build one for each field?
 
You'd put the code in the BeforeUpdate event of the form.

Select "[event procedure]" from the dropdown list and click the "..." button to get to the code window.

You would need to create and if-then statement for each field you want to check.
 
dannyocean, look at thread702-516948 for some ideas. Judge Hopkins

"...like hunting skunks underwater...."
John Steinbeck, The Grapes of Wrath
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top