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

  • Home
  • SEARCH
  • 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 7162285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:42:34+00:00 2026-05-28T13:42:34+00:00

I have 2 forms in my visual basic 2010 project. Both are connected with

  • 0

I have 2 forms in my visual basic 2010 project. Both are connected with an SQL 2008 Server where i keep a db with customers records(name,surname,address, etc).

What i want to do is to give certain criteria in the first form, lets say name,and hit a search button. The program should search the db if the specified name exists.If it exists i want to show the results in the second form. By results i mean the name , surname, address,etc. If it does not exist i want to prompt the user to insert data into the db.

The problem is that i know how to do this work in a single form but not how to make the two forms “communicate” with each other (meaning that one does the search and the other the projection-adding part).

Any help is appreciated

Edit

I am sorry guys but i cannot figured it out. I tried setting the filters but all i get is errors. I will post whatever i have written so far in case someone can help me out. So here it is.
As i stated earlier i know how to search for the data in a single form(lets call it DisplayForm). As Olivier mentioned i have textboxes for the records, a combo box with the search criteria(name , surname,id) and a Search button that perfoms the search and populates the text boxes. The code for the search button is this:

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

    Dim intPosition As Integer


   'Combo box code
    Select Case cboField.SelectedIndex
        Case 0 
            ObjDataView.Sort = "surname"
        Case 1 
            ObjDataView.Sort = "id"
    End Select


    If cboField.SelectedIndex = 0 Then

        intPosition = ObjDataView.Find(txtSearch.Text)
    ElseIf cboField.SelectedIndex = 1 Then

        intPosition = ObjDataView.Find(CType(txtSearch.Text, Integer))
    End If


    If intPosition = -1 Then
        MessageBox.Show("No customer found", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
    Else
        objCurrencyManager.Position = intPosition

    End If
End Sub

I want this procedure be done in a second form (lets call it FormSearch) and populate the textboxes in form DisplayForm. I know that it is easy enough for someone that knows VB but i am tottally a newbie and desperatly need help.
Thanks a lot for any advice

  • 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-05-28T13:42:36+00:00Added an answer on May 28, 2026 at 1:42 pm

    In your display form add this code

    Public Sub SetFilter(name as String)
       ' Set the filter here
    End Sub
    

    In your filter form do this

    DirectCast(Application.OpenForms(0), DisplayForm).SetFilter(NameTextBox.Text)
    

    Here I assume that DisplayForm is your main form and that it’s name is DisplayForm. You would call this in a button click event hanlder, for instance.


    EDIT in response to comment:

    You said that you know how to do it on a single form. I do not know how you do it, but probably you have textboxes for the name, the address, etc. that you are looking for. Then probably you press a button called btnSearch. By pressing this button you trigger

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch_Click.Click
         ' The search logic goes here
    End Sub
    

    What I am telling you is to replace btnSearch_Click by Public Sub SetFilter(name as String) that is public. You would move those search fields and the button to the second form and from there call SetFilter of the first form in order to communicate with it and tell it to search a customer. In my example, I pass only a name, but I left it up to you to pass more parameters as required.

    Assuming that your customer form is called “DisplayForm”, you could access it like this

    Dim cust As DisplayForm
    cust = DirectCast(Application.OpenForms("DisplayForm"), DisplayForm)
    cust.SetFilter(NameTextBox.Text)
    

    My answer was only about the communication between the two forms, assuming that you already managed the other part.


    Searching for “VB.NET Tutorial: Working With Data” on YouTube results in six videos on this subject. Video #3 in particular shows how to use filters.


    EDIT #2. Here is a little more help:

    I do not know how you are opening the two forms. Since you need a reference to the display form in the search form, it is easier to open the search form as the main form at application startup. At Form_Load in the search form, you then open the display form by code

    Code in the search form:

    ' Reference to the display form
    Private _displayForm As DisplayForm
    
    ' Create the display form and open it
    Private Sub SearchForm_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        _displayForm = New DisplayForm()
        _displayForm.Show()
    End Sub
    
    ' Get the search parameters and tell the display form to set the filter
    Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
        Dim field As String, search As Object
    
        Select Case cboField.SelectedIndex
            Case 0
                field = "surname"
                search = txtSearch.Text
            Case 1
                Dim n As Integer
    
                field = "id"
                If Integer.TryParse(txtSearch.Text, n) Then
                    search = n
                Else
                    MessageBox.Show("Please enter a number for id search", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
                    Return
                End IF
        End Select
        _displayForm.SetFilter(field, search)
    End Sub
    

    Code in the display form that actually performs sorting and searching:

    Public Sub SetFilter(ByVal field As String, ByVal search As Object)
        Dim intPosition As Integer
    
        ObjDataView.Sort = field
        intPosition = ObjDataView.Find(search)
        If intPosition = -1 Then
            MessageBox.Show("No customer found", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
        Else
            objCurrencyManager.Position = intPosition
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows Forms project in Visual Studio 2008, which references a library
I have a Windows Forms project in Visual Studio that reads configuration files from
I have a Windows Forms application in C#/Visual Studio 2008 with an IE WebBrowser
Using Visual Studio 2008, c#, .net 2.0. I have a Windows Forms client application
I'm using Visual Basic 2010 Express. I have a form that can be minimized.
A seemingly trivial problem. I have a very basic page in Visual Studio 2010.
I'm developing a Windows Forms Application in Visual Basic .NET with Visual Studio 2008.
I am using VB.NET 2010 (Visual Basic 2010 Express) on a WPF-based project. I
I am using visual studio 2010 and believe I have a project settings issue.
I have been developing a windows form based project in visual basic .NET, moving

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.