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

Require all fields - problem looping with combobox - NEED HELP 1

Status
Not open for further replies.

PROXI

Vendor
Sep 16, 2003
136
US
Hello all. I am trying to validate my form before I update the table. I am getting hung up on the combo boxes. Can someone with a sharper mind than myself please take a look at this and see what is wrong and how to fix it.

Code:
Private Sub cmdSubmit_Click()
   Dim ctl As Control, xCtl
   Dim Msg As String, Style As Integer, Title As String, DL As String
   
   DL = vbNewLine & vbNewLine
   
    Select Case ctl.ControlType
        Case acComboBox, acTextBox
   For Each ctl In Me.Controls
      If ctl.Tag = "Required" And Trim(ctl & "") = "" Then
         Set xCtl = ctl
         Exit For
      End If
   Next
   
   If IsEmpty(xCtl) Then 'All required OK.
      'Your code for printing report
   Else 'At least one required missing.
      Msg = "Required Data for '" & xCtl.Name & "' is missing!" & DL & _
            "Click 'Yes' to go back and enter the data . . ." & DL & _
            "Click 'No' to abort, and cancel printing report & close database. . ."
      Style = vbCritical + vbYesNo
      Title = "Required Data Error! . . ."
      
      If MsgBox(Msg, Style, Title) = vbYes Then
         ctl.SetFocus
      Else
         'Your code for closing database
      End If
   End If

Exit_cmbSubmit_Click:
    Exit Sub

Err_cmbSubmit_Click:
    MsgBox Err.Description
    Resume Exit_cmbSubmit_Click

End Select
End Sub

Thanks in advance.

Thanks,

PROXI
 
Like this ?
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acComboBox, acTextBox
If ctl.Tag = "Required" And Trim(ctl & "") = "" Then
Set xCtl = ctl
Exit For
End If
End Select
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top