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

  • SEARCH
  • Home
  • 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 7603851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:45:30+00:00 2026-05-30T23:45:30+00:00

I have a main form with a register and a few subforms. I’m using

  • 0

I have a main form with a register and a few subforms. I’m using class modules and I save the name of the forms in it, to make the access to them easy. The corresponding variable to access the class gets saved in a module and is set (new) on_load in a form (clsMod). Before the first access my main form calls a function which ‘initializes’ the values in the class module (initial_form), to make them accessible. That works like a charm, so far.

But when I now try to access the value, f.e. with clsMod.detailsControl or clsMod.detailsControl!fieldXy my class module gets initialized again a thus looses all bound objects. I suppose I am not allowed to use Controls / Forms like that? There is no error, except of course ‘Object variable, or with block variable not set’, which occurs afterwards.

Private m_ctldetailsControl As control

Public Sub initial_form()
  Set detailsControl = Forms!mainForm_ufoMainForm
End Sub

Public Property Get detailsControl() As control
  Set detailsControl = m_ctldetailsControl
End Property

Public Property Set detailsControl(ctlDetailsControl As control)
  Set m_ctldetailsControl = ctlDetailsControl
End Property

I narrowed it down to the fact that the class module just gets initialized again, when I access the control-object from the ‘outside’ (I put a timestamp in the Class_Initialize() and can see when there is a new initialization), I just don’t know why. Same happens when I use Form-Objects instead of Control-Objects.

I can eliminate the my code resets the class-module, because it only gets set once during the load process (set clsMod = new clsModification). Everything else inside that class works fine, I can access the property from inside the class without reinitializing itself.

Any ideas or further reading regarding this topic would be greatly appreciated, for any other details just ask!

A few additions:

  • The class variable is located as “public clsMod As clsModuleXy” in a module
  • it gets set in the onLoad Event of my form (set clsMod = new clsModuleXy)
  • set-property works fine (as descriped above)
  • get property works fine inside the class-module (as descriped above)
  • when I use the get property outside of the class module a new instantiation happens (if I set a local control/form to that property or want to access a field)
  • 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-30T23:45:32+00:00Added an answer on May 30, 2026 at 11:45 pm

    I’m guessing that the culprit is that you have declared an instance of this class module As New. I obviously don’t know what the rest of your code looks like, but I imagine the whole process is working something like this:

    1. An instance of this object is declared As New (ie, Dim clsMod As New initial_form).
    2. The Class_Initialize() procedure runs when the new instance (clsMod) is created.
    3. Something causes this instance (clsMod) of the object to go out of scope.
    4. The VBA garbage collector cleans up this object instance (clsMod) which is no longer in use.
    5. The Class_Terminate() procedure runs when the instance (clsMod) is cleaned up.
    6. You try to access clsMod. That variable is Nothing because the GC cleaned it up. However, you declared it As New so a brand new instance of initial_form is created and assigned to the object variable clsMod.
    7. The Class_Initialize() procedure runs again for this brand new instance.

    Without seeing the rest of your code, I can’t say for sure this is the problem. But based on the symptoms you posted, this would explain the behavior.

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

Sidebar

Related Questions

I have a main form with a tab control containing multiple subforms. I need
I have a main form with a lot of inputs. The forms action is
I have a main form and as sub form. I need the main Form
I have a main form, and a floating child form that is non-modal. The
I have a main form and non-modal autocomplete form. How can I prevent the
I have the following scenario I have a main form as MDI parent and
I have WPF Application where I have One main form and other user controls
I've got a situation where I have a main form that pops up an
I hope I can explain this clearly enough. I have my main form (A)
c# .Net 3.5 visual studio 2008, windows xp I have a main form in

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.