access class module from two forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • c2015
    New Member
    • Feb 2008
    • 1

    access class module from two forms

    I need help with some VB code. I will keep it generic and clear as possible.

    I have two forms lets call Form1 and Form2
    I have a class module (CM) and a sub class module (SCM) instantiated in the upper module

    CM
    |_> SCM

    Form 2 loads first and accesses SCM through CM
    (everyting OK at this point)
    Form 2 calls Form1 which tries to access SCM while Form2 still communicating
    to the CM.

    Here is the relevent code for Form2:

    Private CM_ref As CM

    (note everything in Form2 is able to communicate to theCM no problems)

    Call Form1.Sub


    Here is the relevent code for Form1:

    Private Sub Form_Load()

    CM_ref.String1 = "String"
    (note this is when I receive an invaid use of property error)

    End Sub

    Public Property Get CM_ref() As CM
    Set CM_Ref= CM
    End Property

    Public Property Let CM_ref (ByRef b As CM)
    CM_ref = b
    End Property

    Here is the relevent code for the CM:

    Private m_SCM As clsSCM

    Public Property Get SCM() As clsSCM
    If m_SCM Is Nothing Then
    Set m_SCM = New clsSCM
    End If
    Set SCM = m_SCM
    End Property

    Public Property Get String1() As UserDefinedStri ngType
    String1 = SCM.String
    End Property

    Public Property Let String1(ByVal n As UserDefinedStri ngType)
    SCM.String = n
    End Property

    Here is the relevent code in SCM:

    Private m_String As UserDefinedStri ngType

    Public Property Get String1() As UserDefinedStri ngType
    String1 = m_String
    End Property

    Public Property Let String1(ByVal int As UserDefinedStri ngType)
    String = int
    End Property

    Help: What I want to have happen it when Form1 is called and loads,
    for Form1 to create a reference to SCM to access it's functions not to
    create a new instance of SCM. It should be able to communicate while
    Form2 has access to CM.SCM also both would have access to Functions and
    update property values that the other form would then see. Any help
    or advice would be greatly appreciated. let me know if you need any
    other information to figure out what I'm doing wrong to generate this error.
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Hi there!

    I am not sure why it is not working but would like to tell you what I think may work.

    Form1 should be able to see Form2, if you say something like:

    [CODE=VB]

    Form1.Text1.Tex t = Form2.Text1.Tex t

    [/CODE]

    Which means that you'd have to tell vb, within the module(s), to talk to Form1/ Form2 fields...

    Please continue to stay tuned for added hits on this one.

    In a bit!

    Comment

    Working...