Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem passing field from parent, to child form

Problem passing field from parent, to child form

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasesaleshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    penguin5000
    wrote on last edited by
    #1

    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.

    R S 2 Replies Last reply
    0
    • P penguin5000

      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.

      R Offline
      R Offline
      Robotovich
      wrote on last edited by
      #2

      Try declaring the id variable as public so the child form can access it.

      1 Reply Last reply
      0
      • P penguin5000

        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.

        S Offline
        S Offline
        Scott Serl
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups