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
Re: Open a form from Form1 in "add record mode"
... no one able to assist here?
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
Quote:
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.
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()
Re: Open a form from Form1 in "add record mode"
Quote:
Originally Posted by
Nyatiaju
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.
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()
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.
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.