Results 1 to 8 of 8

Thread: Open a form from Form1 in "add record mode"

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    97

    Open a form from Form1 in "add record mode"

    I am wanting to open an existing form in 'Add Record' mode from another form. In this case from my LoadInfo form - opening FuelInfo form.
    I am using the following code that is not properly working - Can someone assist me please?

    My original code opens the form by using the Menu1 as the Parent form then the child form (FuelInfo) opens. All forms are child of Menu1.

    The commented out area (italicized) of the code works in opening the form but not in 'addnew' status, but it only works on the initial call. Any subsequent calls gives and error.
    The embolden area is the new code I tried but does not work - it gives error 'There is no row at position 0' - . I suspect I am going to have to utilize the parent call I have commented out in some manner but unsure how to do it. Any suggestions?

    Code:
                    Catch ex As Exception
                        If (LoadFormCount < 2) Then
                            MessageBox.Show(("Fuel Record for Load Number: " + tbPETSLoadNumber.Text + " does not exist.") & Environment.NewLine &
                                            ("Please create a record for Load Number: " + tbPETSLoadNumber.Text + " on the Fuel Form.") & Environment.NewLine + Environment.NewLine &
                                            "You will now be re-directed to the FUEL Page to create the record.",
                                            "Critical Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                            My.Forms.FuelInfo.FuelTableBindingSource.AddNew()
                            'MenuForm.FuelData()
                        End If
                        LoadFormCount = 0
                        Return
                    End Try
    Last edited by K3JAE; May 21st, 2020 at 10:44 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    97

    Re: Open a form from Form1 in "add record mode"

    ... no one able to assist here?

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Open a form from Form1 in "add record mode"

    You're using some pretty non-standard terminology, and have an odd example, so it may be that nobody could quite understand what you meant. For example, I've been working in .NET for almost two decades, and my best guess for what this
    I am wanting to open an existing form in 'Add Record' mode from another form.
    means is that you are misunderstanding something about what forms are or how they work. I've never heard of 'Add Record' mode, and can't guess what that could mean to you.

    You also show an exception catch statement, but not the Try block with the code that threw the exception in the first place. You have a variable with a reasonable name, but we have no idea what it means and what value it holds. After all the code you showed will do nothing at all under either of these scenarios:

    1) No exception was thrown.

    2) LoadFormCount >= 2.

    Even if there IS an exception, and LoadFormCount is less than 2, all you appear to be doing is adding something to FuelInfo, but what you are adding doesn't look like it could possibly mean anything.
    My usual boring signature: Nothing

  4. #4
    New Member
    Join Date
    May 2020
    Posts
    8

    Re: Open a form from Form1 in "add record mode"

    If form is already open, then code below works.
    Code:
    Dim frm As FuelInfo = My.Application.OpenForms.Item("FuelInfo")
            FuelInfo.FuelTableBindingSource.AddNew()

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    97

    Re: Open a form from Form1 in "add record mode"

    Quote Originally Posted by Nyatiaju View Post
    If form is already open, then code below works.
    Code:
    Dim frm As FuelInfo = My.Application.OpenForms.Item("FuelInfo")
            FuelInfo.FuelTableBindingSource.AddNew()
    The form would not be already open when it is called.

  6. #6
    New Member
    Join Date
    May 2020
    Posts
    8

    Re: Open a form from Form1 in "add record mode"

    To Open New form with new record
    Code:
    Dim frm As New FuelInfo
            frm.Show()
            frm.TblFuelBindingSource.AddNew()

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    97

    Re: Open a form from Form1 in "add record mode"

    OK that works but does not resolve my initial request... it opens the form OUTSIDE of the MDI Parent. I need it to open as a child INSIDE the MDI Parent.
    Last edited by K3JAE; May 22nd, 2020 at 02:42 PM. Reason: corrected info

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    97

    Re: Open a form from Form1 in "add record mode"

    I have it resolved. Thanks for the help... the Info provided here got me on the correct path. Thanks again everyone.

Tags for this Thread

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