Good day!

I want to check all txtbox and combox(style=2) in a form when the user click save. If one textbox or one combobox is not fill in then i will show a message that cannot submit. One or more fields requires entry.I dont know whats wrong with my code below.It does not read even if textbox or combobox is null.

Public Sub clarifydata()
For Each txt In Me.Controls
    If TypeOf txt Is TextBox Or TypeOf txt Is ComboBox Then
       If txt.Text = "" Then
            toclear = toclear + "0"
        Else
            toclear = toclear + "1"
        End If
    End If
Next
    If toclear Like "1" Then
        clarifyclear = True
    Else
        clarifyclear = False
    End If
End Sub

Any reply will be very appreciated.!

God bless on this mother earth.

Dim C As Control
For Each C In Me.Controls
  If C Is TextBox Then
    If Trim(C.Text) = "" Then
      C.SetFocus
      msgbox "message"
      Exit For
  ElseIf C Is ComboBox Then
    If Trim(C.Text) = "" Then
      C.SetFocus
      Exit For
    End If
  End If
Next C

Or...

If C Is TextBox Or C Is ComboBox Then

As you have done

Good Luck

Dim C As Control
For Each C In Me.Controls
  If C Is TextBox Then
    If Trim(C.Text) = "" Then
      C.SetFocus
      msgbox "message"
      Exit For
  ElseIf C Is ComboBox Then
    If Trim(C.Text) = "" Then
      C.SetFocus
      Exit For
    End If
  End If
Next C

Or...

If C Is TextBox Or C Is ComboBox Then

As you have done

Good Luck

I know this will owrk even if i havent try this yet. Thank you very much.

I have replied to your other post... It will give you a start... Incase you get stuck let me know.... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.