CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2007
    Posts
    68

    Question MDI Application Help

    Hi All

    I have an Application with 2 forms

    Form 1 = FrmWindow this is an MdiParent Form
    Form 2 = FrmInput this is an MdiChild Form

    On Form 1 I have a Menu thats says New Input the onclick event looks as follows.

    Code:
    Dim ChildForm As Form
    ChildForm = My.Forms.FrmInput
    ChildForm.MdiParent = Me
    ChildForm.Show()
    This works and opens the FrmInput as a child of FrmWindow.

    On the form FrmInput I have two Textbox Controls and 2 Button Controls

    Textbox 1 = TxtName
    Textbox 2 = TxtEmail
    Button 1 = BtnSave
    Button 2 = BtnExit

    On the On Click event of BtnSave I have
    Code:
     SaveInformation()
    The Public Sub for SaveInformation Looks like this.

    Code:
    Public Sub SaveInformation()
            Dim con As New SqlClient.SqlConnection()
            Dim com As New SqlClient.SqlCommand
            con.ConnectionString = SQLConnection()
            con.Open()
            com.Connection = con
            com.CommandText = "INSERT INTO TblInformation(Name,Email_Address) VALUES(@Name,@Email_Address)"
            com.Parameters.AddWithValue("@Name", My.Forms.FrmInput.TxtName.Text)
            com.Parameters.AddWithValue("@Email_Address", My.Forms.FrmInput.TxtEmail.Text)
            com.ExecuteNonQuery()
            con.Dispose()
            com.Dispose()
        End Sub
    So when you click the save button it inserts a new record into the table TblInformation on my SQL database, everything works great. Now my problem is I want to be able to open multiple instances of the form FrmInput at the same time.

    So I changed the New Input button to the following

    Code:
    Dim ChildForm As Form
    Dim ChildInstance As New FrmInput
            ChildForm = ChildInstance
            ChildForm.MdiParent = Me
            ChildForm.Show()
    This works and I can now open up mutiple instances of the form FrmInput, what I cant figure out is how to save the information on a particular instance.

    Any and all help is apprecited.

    Cheers

    Djbell

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: MDI Application Help

    Where are you calling the save routine from?

  3. #3
    Join Date
    Apr 2007
    Posts
    68

    Re: MDI Application Help

    Hi DataMiser

    I am calling the save routine from a Module I have created specifically for Data Functions

    Cheers

    Djbell

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: MDI Application Help

    The code can be in a module or class but should be called from the instance of the form in question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured