471,122 Members | 1,114 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

access class module from two forms

1
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 UserDefinedStringType
String1 = SCM.String
End Property

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

Here is the relevent code in SCM:

Private m_String As UserDefinedStringType

Public Property Get String1() As UserDefinedStringType
String1 = m_String
End Property

Public Property Let String1(ByVal int As UserDefinedStringType)
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.
Feb 25 '08 #1
1 1387
Dököll
2,364 Expert 2GB
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Form1.Text1.Text = Form2.Text1.Text
  3.  
  4.  
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!
Feb 26 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Peter Frost | last post: by
49 posts views Thread by Yannick Turgeon | last post: by
55 posts views Thread by AnandaSim | last post: by
19 posts views Thread by Jamey Shuemaker | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.