Problem passing field from parent, to child form
-
Wonder if anybody can point me in the right direction? I'm wondering what I'm doing wrong. I have a parent and child form. On the parent form, I have a CustomerID field - which is a CustomerID field in my tblCustomersParent table my Access database. I have a similar field in tblCustomersChild to create the relationship, and a field on the child form to display it. This CustomerID field is passed to the child form using:
Me.frmCustomerContacts = New CustomerContacts frmCustomerContacts.ValueFromParent = Me.CustomerID.Text frmCustomerContacts.ShowDialog()
The customer ID is then copied to the child form using:Public WriteOnly Property ValueFromParent() As String Set(ByVal Value as String) Me.CustomerID.Text = Value End Set End Property
This works well except for when tblCustomersChild does not have an existing entry for that CustomerID. For example, if I create a new customer (or even if I have an existing customer entry in tblCustomersParent), and then wish to add contacts for that customer, the CustomerID field on the child form does not get populated because tblCustomersChild does not have any corresponding entries already recorded. I can enter a record in Access to make it work, and it does carry that CustomerID through from parent to child, and I can add new contact records to the child form. I am using a standard SELECT statement to collect the data for the child form based on what the CustomerID field is on the parent form. I'm using VB.NET 2003. -
Wonder if anybody can point me in the right direction? I'm wondering what I'm doing wrong. I have a parent and child form. On the parent form, I have a CustomerID field - which is a CustomerID field in my tblCustomersParent table my Access database. I have a similar field in tblCustomersChild to create the relationship, and a field on the child form to display it. This CustomerID field is passed to the child form using:
Me.frmCustomerContacts = New CustomerContacts frmCustomerContacts.ValueFromParent = Me.CustomerID.Text frmCustomerContacts.ShowDialog()
The customer ID is then copied to the child form using:Public WriteOnly Property ValueFromParent() As String Set(ByVal Value as String) Me.CustomerID.Text = Value End Set End Property
This works well except for when tblCustomersChild does not have an existing entry for that CustomerID. For example, if I create a new customer (or even if I have an existing customer entry in tblCustomersParent), and then wish to add contacts for that customer, the CustomerID field on the child form does not get populated because tblCustomersChild does not have any corresponding entries already recorded. I can enter a record in Access to make it work, and it does carry that CustomerID through from parent to child, and I can add new contact records to the child form. I am using a standard SELECT statement to collect the data for the child form based on what the CustomerID field is on the parent form. I'm using VB.NET 2003.Try declaring the id variable as public so the child form can access it.
-
Wonder if anybody can point me in the right direction? I'm wondering what I'm doing wrong. I have a parent and child form. On the parent form, I have a CustomerID field - which is a CustomerID field in my tblCustomersParent table my Access database. I have a similar field in tblCustomersChild to create the relationship, and a field on the child form to display it. This CustomerID field is passed to the child form using:
Me.frmCustomerContacts = New CustomerContacts frmCustomerContacts.ValueFromParent = Me.CustomerID.Text frmCustomerContacts.ShowDialog()
The customer ID is then copied to the child form using:Public WriteOnly Property ValueFromParent() As String Set(ByVal Value as String) Me.CustomerID.Text = Value End Set End Property
This works well except for when tblCustomersChild does not have an existing entry for that CustomerID. For example, if I create a new customer (or even if I have an existing customer entry in tblCustomersParent), and then wish to add contacts for that customer, the CustomerID field on the child form does not get populated because tblCustomersChild does not have any corresponding entries already recorded. I can enter a record in Access to make it work, and it does carry that CustomerID through from parent to child, and I can add new contact records to the child form. I am using a standard SELECT statement to collect the data for the child form based on what the CustomerID field is on the parent form. I'm using VB.NET 2003.Why not just pass in the value to the constructor of the form: Me.frmCustomerContacts = New CustomerContacts(Me.CustomerID.Text) On the chidl form, have a read-only property: Private _customerID As String Public ReadOnly Property CustomerID as String Get Return _customerID End Get End Property Modify the constructor of the child form: Public Sub New(ByVal CustomerID As String) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call _customerID = CustomerID End Sub