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 Westi 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(s), any of three meets the requirement? 2

Status
Not open for further replies.

LD1010

Technical User
Dec 6, 2001
78
US
I have an entry form with 3 cbo's. Entering a value in any of the cbo's, or all would meet the validation requirement to save the record. But if none of the cbo's is populated the record could not be saved. Can anyone help me with some code to make this work?

Any help would be much appreciated.
 
How about simply checking them in the BeforeUpdate event of the form? If at least 1 of the cbo's has a value then let it update, otherwise Cancel = True the event!

RuralGuy (RG for short) aka Allan Bunch MS Access MVP acXP winXP Pro
Please respond to this forum so all may benefit
 
How are ya LD1010 . . .

[ol][li]Put a question mark [blue]?[/blue] in the tag property of the three comboboxes ([blue]no quotations please![/blue]).[/li]
[li]In the forms [blue]Before Update[/blue] event, copy/paste the following:
Code:
[blue]   Dim ctl As Control, flg As Boolean, DL As String
   
   DL = vbNewLine & vbNewLine
   
   For Each ctl In Me.Controls
      If ctl.Tag = "?" Then
         If Trim(ctl & "") <> "" Then
            flg = True
            Exit For
         End If
      End If
   Next
   
   If flg = False Then
      MsgBox "Can't Save Record!" & DL & _
             "One of the comboboxes has to have data!" & DL & _
             "You'll have to go back and correct this.", _
             vbCritical + vbOKOnly, _
             "Missing Data Detected! . . ."
      [green]'Set focus to one of the comboboxes[/green]
      Cancel = True
   End If[/blue]
[/li][/ol]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thank you AceMan, that works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top