Calling/caller forms

McShmack

Member
Joined
Aug 16, 2011
Messages
7
Programming Experience
Beginner
I have a form name frmRateConfirm that has a combobox on it that is bound to a table. This combo box fills text boxes on the form based on the selection. If the user types in the box and the item is not there I then call a data entry form so that the record may be added to the table and then return control back to frmRateConfirm. Works Great. My question is, I have several other forms for example frmRateConfirm1P2D that has the same design and behaves identically except for that when the dataentry form is closed control goes back to frmRateConfirm and not frmRateConfirm1p2D or any other calling form, how can I make sure that the right calling form is the one that receives control after closing the dataentry form? Code is as follows;

here is the code for one of the calling forms combobox;

Dim myForm As frmCarriers


Private Sub cboCarrierName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCarrierName.Leave
Dim myValue As New Object

Dim msg As MsgBoxResult
myValue = cboCarrierName.SelectedValue
If myValue = Nothing Then

msg = MsgBox(
"Do you want to add this Carrier to the database?", MsgBoxStyle.OkCancel)
If msg = MsgBoxResult.Ok Then

If myForm Is Nothing Then

myForm =
New frmCarriers(Me)
End If

myForm.Show()
Me.Hide()
Else

myForm.Close()
End If

End If

End Sub


And here is the code from the dataentry form

Private CallingForm As Object


Private Sub btnSaveExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveExit.Click
Me.TblCarriersBindingSource.AddNew()
Me.TblCarriersBindingNavigatorSaveItem.PerformClick()
Dim myForm As Form
myForm = CallingForm
myForm.Visible =
True
Me.Close()
End Sub
Public Sub New(ByVal caller As Object)
MyBase.New()
InitializeComponent()
' Note which form has called this one
CallingForm = caller
End Sub


Any assistance will be very much appreciated. I know I got some logic messed up

Thanks,

McShmack
 
Try opening the data entry form as showdialog which would prevent any other actions from taking place until the dialog is closed.
This would return to the calling form only.
 
Back
Top