Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3981602
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:25:46+00:00 2026-05-20T05:25:46+00:00

Lets say I have a custom collection and a custom object that have a

  • 0

Lets say I have a custom collection and a custom object that have a Parent-Child relationship

I have a userform where the user names the collection and provides input for other properties of the collection. When they click “Add Parent” the click event is handled and calls the following function:

Public Function AddParent()

    Dim newParent As clsParent

    Set newParent = New clsParent

    'Add Parent Properties'

        With frmAddParent
            newParent.Name = .cboParentName.Value
            newParent.Width = .txtParentWidth.Value
            newParent.Xslope = .txtParentCrossSlope.Value
        End With

    'show the form for creating the Child Object'

    frmAddLaneMaterial.Show

End Function

The user then sees a new form for creating a Child object. When the user clicks “Add Child” the event is handled and calls the following function:

Public Function AddChild()

    Dim newChild As clsChild
    Set newChild = New clsChild

        'Add child Properties'

        With frmAddChild

            newChild.Name = .cboParentName.Value
            newChild.LayerNumber = .cboLayerNum.Value
            newChild.xSlope = newParent.Xslope

        End With

    'Add the new child to the parent collection'

    newParent.Add newChild

End Function 

And then the user needs to be able to return to the userform and add another child.

The lines that won’t work are:

            newChild.xSlope = newParent.Xslope

and:

newParent.Add newChild

I get an ‘object required’ error.

How do I/where do I add the child to the Parent Collection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:25:47+00:00Added an answer on May 20, 2026 at 5:25 am

    First of all, newParent is local to the AddParent function so AddChild has no visibility of it. To fix that, you would need to move Dim newParent As clsParent out of the AddParent function and make it a module-level variable. This assumes that AddParent and AddChild are in the same module.

    Secondly, newParent.Add newChild will only work if you have written an Add method in clsParent. If you have not then you’ll need to write one. I have no idea how you plan on using it, but the following code is pretty generic and should get you pointed in the right direction. This code would go in the clsParent module:

    Private m_oChildren As Collection
    
    Sub Add(Child As clsChild)
        If m_oChildren Is Nothing Then Set m_oChildren = New Collection
        m_oChildren.Add Child
    End Sub
    

    This would build a private collection of clsChild objects that you would manipulate using additional methods or expose via Property Get.

    UPDATE: To address your comment, if you want to keep multiple parents you’ll need to add a collection for that. For example:

    Dim Parents As Collection
    
    Public Function AddParent()
    Dim newParent As clsParent
        Set newParent = New clsParent
    
        'Add Parent Properties'
        With frmAddParent
            newParent.Name = .cboParentName.Value
            newParent.Width = .txtParentWidth.Value
            newParent.Xslope = .txtParentCrossSlope.Value
        End With
    
        'Initialize the collection of Parents if it has not already been done'
        If Parents Is Nothing Then Set Parents = New Collection
        'Add the new parent object to the Parents collection'
        Parents.Add newParent
    
        'show the form for creating the Child Object'
        frmAddLaneMaterial.Show
    End Function
    
    
    Public Function AddChild()
    Dim newChild As clsChild
        Set newChild = New clsChild
    
        'Add child Properties'
        With frmAddChild
            newChild.Name = .cboParentName.Value
            newChild.LayerNumber = .cboLayerNum.Value
            newChild.xSlope = newParent.Xslope
        End With
    
        'Add the new child to the most recently added parent in the parent collection'
        Parents.Item(Parents.Count).Add newChild
    
    End Function
    

    Of course, now you have another collection to keep track of. It gets really tricky keeping track of multiple instances of forms (which I assume is what you are doing) and it is easy to suddenly find yourself with an unmanageable mess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a custom control called FooBox. It is just a square
Lets say I have an ActionScript class: MyClass and that class has data in
Lets say you have a relational DB table like INVENTORY_ITEM. It's generic in the
I have an app that makes use of 'django-registration' a custom built model named
I have a strongly typed list of custom objects, MyObject , which has a
I want to put a custom control inside the view for my NSCollectionViewItem. Lets
I've created a custom control for MahTweets which simplifies/unifies the look of each update
I wanted to make a special version of shared_ptr that would perform specific operations
Howdy, I am a programmer that has worked almost exclusively with c++/c#/vbs and am
Summary : I need to authorize pages based upon the data present in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.