Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How can I take one record from one form and the values to open another form?

How can I take one record from one form and the values to open another form?

Scheduled Pinned Locked Moved Visual Basic
questiondatabasetutorialannouncement
6 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    waner michaud
    wrote on last edited by
    #1

    :~I have a form that takes info from the user when all the entry is correct, the user can open another form for the next process. What I mean is that let's say a registration form is open to create a registration record, when it's done, a complaint form is then open to create a complaint record based on the registration record. registration is a parent form and complaint is a child form. the open registration record must be parsed to the complaint form for it to be opened. the child form must be able to update the database and create a new record form its instance. can anyone guide.. Best regard, waner

    T T 2 Replies Last reply
    0
    • W waner michaud

      :~I have a form that takes info from the user when all the entry is correct, the user can open another form for the next process. What I mean is that let's say a registration form is open to create a registration record, when it's done, a complaint form is then open to create a complaint record based on the registration record. registration is a parent form and complaint is a child form. the open registration record must be parsed to the complaint form for it to be opened. the child form must be able to update the database and create a new record form its instance. can anyone guide.. Best regard, waner

      T Offline
      T Offline
      Tom Deketelaere
      wrote on last edited by
      #2

      Pass the 'registration' info from the parent form to the child form in the child forms constructor or property's (constructor is safest way since then you have to pass them) Pseudo code:

      class form1

      private sub button1_click
      'validate the registration info
      if valid then
      dim frm as new form2(param1,param2,...)
      frm.showdialog
      end if
      end sub

      end class

      class form2

      public sub new (param1 as ..., param2 as ..., ...)
      initializecomponent
      'do more code here with the params
      end sub

      end class

      W 1 Reply Last reply
      0
      • T Tom Deketelaere

        Pass the 'registration' info from the parent form to the child form in the child forms constructor or property's (constructor is safest way since then you have to pass them) Pseudo code:

        class form1

        private sub button1_click
        'validate the registration info
        if valid then
        dim frm as new form2(param1,param2,...)
        frm.showdialog
        end if
        end sub

        end class

        class form2

        public sub new (param1 as ..., param2 as ..., ...)
        initializecomponent
        'do more code here with the params
        end sub

        end class

        W Offline
        W Offline
        waner michaud
        wrote on last edited by
        #3

        thanks, this is what I have done. In the registration form that is the parent form Private sub CreateAComplaint_Click Dim row As IGRegistrationDataSet.RegistrationRow row = CType(CType(Me.RegistrationBindingSource.Current, DataRowView).Row, IGRegistrationDataSet.RegistrationRow) Dim frm As New ComplaintProfile(Me.IGRegistrationDataSet, row.Reg_ID) frm.ShowDialog() end sub int the complaint form that is the child form, I have this Sub New(ByVal ds As IGRegistrationDataSet, ByVal id As Integer) ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Me.RegistrationBindingSource.DataSource = ds Me.RegistrationBindingSource.Filter = "Reg_ID = " & id.ToString End Sub * One dataset and one table.. when save on the child form nothing happens to the data base, I must go back to the parent form for the changes to occur since the child form record is in memory. I want to update the database from both the parent and the child. **I am open to use another logic where I use seperate datasets and tables so long the child form is open from the parent.. e.i. Registration record is fine then load the complaint form to create a complaint for this particular registration.. I hope I make myslef clear.. Thanks, Best Regard

        A 1 Reply Last reply
        0
        • W waner michaud

          thanks, this is what I have done. In the registration form that is the parent form Private sub CreateAComplaint_Click Dim row As IGRegistrationDataSet.RegistrationRow row = CType(CType(Me.RegistrationBindingSource.Current, DataRowView).Row, IGRegistrationDataSet.RegistrationRow) Dim frm As New ComplaintProfile(Me.IGRegistrationDataSet, row.Reg_ID) frm.ShowDialog() end sub int the complaint form that is the child form, I have this Sub New(ByVal ds As IGRegistrationDataSet, ByVal id As Integer) ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Me.RegistrationBindingSource.DataSource = ds Me.RegistrationBindingSource.Filter = "Reg_ID = " & id.ToString End Sub * One dataset and one table.. when save on the child form nothing happens to the data base, I must go back to the parent form for the changes to occur since the child form record is in memory. I want to update the database from both the parent and the child. **I am open to use another logic where I use seperate datasets and tables so long the child form is open from the parent.. e.i. Registration record is fine then load the complaint form to create a complaint for this particular registration.. I hope I make myslef clear.. Thanks, Best Regard

          A Offline
          A Offline
          Andy Missico
          wrote on last edited by
          #4

          I have no clear answer, but I do have some comments to help you simplify what you are doing. 0) Use a BindingSource. See documentation and walk-throughs. 1) Just pass the row. There is no need for handling the data set then filtering or anything else. You can get to the table and data set from the row. 2) Manually bind to the row using a BindingSource. In some cases, it is easier to create a class to wrap the data row and handle the business rules. 3) When user clicks okay you may have to call row.AcceptChanges. This depends on how you data bind. 4) You may want to consider overriding the ShowDialog method as in ShowDialog(row As DataRow). Usually, it is easier because it allows you some setup and clean-up. For example, ...

          Private \_row As DataRow
          
          Public Overloads Sub ShowDialog(ByVal row As DataRow)
              Dim iResult As DialogResult
          
              \_row = row
              \_\_bindingSource.DataSource = row
          
              \_row.BeginEdit()
              'other setup
          
              iResult = MyBase.ShowDialog
          
              'clean-up
              If iResult = System.Windows.Forms.DialogResult.OK Then
                  \_row.AcceptChanges()
              Else
                  \_row.CancelEdit()
              End If
          
          End Sub
          
          1 Reply Last reply
          0
          • W waner michaud

            :~I have a form that takes info from the user when all the entry is correct, the user can open another form for the next process. What I mean is that let's say a registration form is open to create a registration record, when it's done, a complaint form is then open to create a complaint record based on the registration record. registration is a parent form and complaint is a child form. the open registration record must be parsed to the complaint form for it to be opened. the child form must be able to update the database and create a new record form its instance. can anyone guide.. Best regard, waner

            T Offline
            T Offline
            Tiyani Miyambo
            wrote on last edited by
            #5

            on the current form you in for example under the button dim f as new form2 " f brings the attribute of the form you want to display the value "me. is the current form you in so the value on the current form will go to tht next form when you click the button f.textbox1.text = me.textbox1.text f.showdialog this statement must be set under

            W 1 Reply Last reply
            0
            • T Tiyani Miyambo

              on the current form you in for example under the button dim f as new form2 " f brings the attribute of the form you want to display the value "me. is the current form you in so the value on the current form will go to tht next form when you click the button f.textbox1.text = me.textbox1.text f.showdialog this statement must be set under

              W Offline
              W Offline
              waner michaud
              wrote on last edited by
              #6

              Hi Tiyani, Thanks a lot. I think that I am moving along. I was able to parse the textboxes record and along the primary Id key that I need to the other form.. The other form has a table that consists of the foreign key from the parent table and other columns. so when I click save on the child form, only the records from that are pertaining to the child table and dataset get saved to the database. Not the record I parsed from the parent table.. How can I get all the input from the form the to get saved.. Here is my my saved function to look at to see where I go wrong: Function Save() As Boolean Dim saved As Boolean = False Dim errors As Integer = 0 Me.Validate() 'Parent Tables where I get the record to load the other form Me.RegistrationBindingSource.EndEdit() Me.RegistrationTableAdapter.Update(Me.Commission1DataSet.Registration) 'child Table Me.Case_fileBindingSource.EndEdit() Me.Case_fileTableAdapter.Update(Me.Case_fileDS.case_file) Dim DeletedCaseFile As case_fileDS.case_fileDataTable = _ CType(Case_fileDS.case_file.GetChanges(Data.DataRowState.Deleted), case_fileDS.case_fileDataTable) Dim NewCaseFile As case_fileDS.case_fileDataTable = _ CType(Case_fileDS.case_file.GetChanges(Data.DataRowState.Added), case_fileDS.case_fileDataTable) Dim ModifiedCaseFile As case_fileDS.case_fileDataTable = _ CType(Case_fileDS.case_file.GetChanges(Data.DataRowState.Modified), case_fileDS.case_fileDataTable) If Me.Case_fileDS.HasChanges Then Try If DeletedCaseFile IsNot Nothing Then Me.Case_fileBindingSource.EndEdit() Me.Case_fileTableAdapter.Update(DeletedCaseFile) End If 'Parent Tables Me.RegistrationBindingSource.EndEdit() Me.RegistrationTableAdapter.Update(Me.Commission1DataSet.Registration) 'child Table Me.Case_fileBindingSource.EndEdit() Me.Case_fileTableAdapter.Update(Me.Case_fileDS.case_file) If NewCaseFile IsNot Nothing Then Me.Case_fileBindingSource.EndEdit() Me.Case_fileTableAdapter.Update(NewCaseFile) End If If ModifiedCaseFile IsNot Nothing Then Me.Case_fileBindingSource.EndEdit() Me.Case_fileTableA

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups