Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9112711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:48:01+00:00 2026-06-17T03:48:01+00:00

I want to check the controls in my Form is empty or not… I

  • 0

I want to check the controls in my Form is empty or not… I have a long code for that. I give code given below.

Public totflag As Boolean
Private Sub BTNSAVE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTNSAVE.Click
    CheckMyControls()
    If totflag = False Then
        MessageBox.Show("Give Compleate Data!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        coloring()
    ElseIf totflag = True Then
        MessageBox.Show("Success", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End If
End Sub
Public Sub coloring()
    Dim txt, cmb, mtxt, rtxt As Control
    For Each txt In EMPGBDATA.Controls
        If TypeOf txt Is TextBox Then
            If txt.Text = "" Then
                txt.BackColor = Color.Red
            End If
        End If
    Next
    For Each cmb In EMPGBDATA.Controls
        If TypeOf cmb Is ComboBox Then
            If cmb.Text = "Select" Then
                cmb.BackColor = Color.Red
            End If
        End If
    Next
    For Each mtxt In EMPGBDATA.Controls
        If TypeOf mtxt Is MaskedTextBox Then
            If mtxt.Text = "" AndAlso mtxt.Name <> "MTXTPFESI" Then
                mtxt.BackColor = Color.Red
            End If
        End If
    Next
    For Each rtxt In EMPGBDATA.Controls
        If TypeOf rtxt Is RichTextBox Then
            If rtxt.Text = "" Then
                rtxt.BackColor = Color.Red
            End If
        End If
    Next

End Sub
Public Function CheckMyControls() As Boolean
    Dim txt, cmb, mtxt, rtxt As Control
    Dim flagtxt, flagcmb, flagmtxt, flagrtxt As Boolean
    flagtxt = False
    For Each txt In EMPGBDATA.Controls
        If TypeOf txt Is TextBox Then
            If txt.Text = "" Then
                flagtxt = True
            End If
        End If
    Next
    flagcmb = False
    For Each cmb In EMPGBDATA.Controls
        If TypeOf cmb Is ComboBox Then
            If cmb.Text = "Select" Then
                flagcmb = True
            End If
        End If
    Next
    flagmtxt = False
    For Each mtxt In EMPGBDATA.Controls
        If TypeOf mtxt Is MaskedTextBox Then
            If mtxt.Text = "" AndAlso mtxt.Name <> "MTXTPFESI" Then
                flagmtxt = True
            End If
        End If
    Next
    flagrtxt = False
    For Each rtxt In EMPGBDATA.Controls
        If TypeOf rtxt Is RichTextBox Then
            If rtxt.Text = "" Then
                flagrtxt = True
            End If
        End If
    Next
    If flagtxt = True Or flagcmb = True Or flagmtxt = True Or flagrtxt = True Then
        totflag = False
    Else
        totflag = True
    End If
    Return totflag
End Function

Actually i don’t want to check one PFESI textbox. If it is empty or not. This is a masked text box. My problem is when i press the submit button with all controls have data, it shows the messsage box “Give Complete Data!”. Controls without data also shows the same message. Please try to check the code and give me solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:48:02+00:00Added an answer on June 17, 2026 at 3:48 am

    You are trying to do it too complicated.
    I am not in front of the computer so maybe the code have minor errors:

    If CheckMyControls() = False Then
            MessageBox.Show("Give Compleate Data!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            coloring()
        Else
            MessageBox.Show("Success", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    
    End Sub
    
    Public Sub coloring()
        For Each cntrl In Me.Controls
            Select Case cntrl.GetType
                Case GetType(ComboBox)
                    If cntrl.Text = "Select" Then
                        cntrl.BackColor = Color.Red
                        Exit For
                    End If
                Case GetType(MaskedTextBox)
                    If cntrl.Text = "" AndAlso cntrl.Name <> "MTXTPFESI" Then
                        cntrl.BackColor = Color.Red
                    End If
                Case Else
                    If cntrl.Text = "" Then
                        cntrl.BackColor = Color.Red
                    End If
    
            End Select
        Next
    
    End Sub
    
    Public Function CheckMyControls() As Boolean
        Dim bEmptyControlFlag As Boolean
        For Each cntrl In Me.Controls
            Select Case cntrl.GetType
                Case GetType(ComboBox)
                    If cntrl.Text = "Select" Then
                        bEmptyControlFlag = True
                        Exit For
                    End If
                Case Else
                    If cntrl.Text = "" Then
                        bEmptyControlFlag = True
                    End If
    
            End Select
        Next
    
        Return Not bEmptyControlFlag
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check which port is used, when the port is not explicitly
I want to check if my many column in datagridview is empty. here my
I have this array (JQuery) where I add all my form's controls, it looks
I have a class which generates a form and controls. The controls vary between
Technologies: C#, .Net, Winforms I have a main form that pulls data from a
I have windows application in c# with a form with 7 text box that
I have a MDI parent form. When user presses Enter I want the Application
I want to go through all the check boxes in form.tab and mark them
HI, I want to customize the existing win-form tool-tip control to host child controls
I have a Windows Form that contains only buttons . The final goal is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.