Solved

referencing MDI Child control from bas module

Posted on 2002-07-02
10
289 Views
Last Modified: 2010-05-18
I have an MDI child form which has a textbox. normally referenced using

frmR.txtMesgWindow.text = frmR.txtMesgWindow.text & Foo

where frmR is the variable referencing to the child form (frmMQ) in the MDI parent.

this child form picks up a message from MSMQ (should not affect anything) and passes it to a sub in a generic bas module, this sub then outputs the message to a textbox in either the originating MDI Child or to another MDI Child, depending on content.

however, using frmR.txtMesgWindow.text inside the bas module raises a variable not defined error. (frmR word is highlighted in debug mode!)

using
frmMQ.txtMesgWindow.text = frmMQ.txtMesgWindow.text & Foo causes a totally new form to appear, so thats not right, and is also not usable if i have multiple instances of frmMQ in the MDI application.

using "Public frmR as frmMQ" inside frmMain doesnt make a difference either.

thanks very much for assistance.
0
Comment
Question by:JooZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7124157
You should check with is the startup form. If the child window is start up (project properties).
Then, the Main MDI form has a property saying AutoShowChildren (or similar...), which should be set to false.
Then, using Public frmR as frmMQ could make the difference, but if I understood correctly, you might have several frmMQ forms? You could then loop the forms collection to find the relevant frmMQ form.

CHeers
0
 

Author Comment

by:JooZ
ID: 7124181
thanks for the prompt comment, angellll

startup sub is Sub Main in frmMain , which is necesary to start instantiating a whole bunch of other subs and as well as to load the child forms.

autoshowchildren was set to true, but i call frmXXX.show for every form in load anyway, so i'm not sure if it makes a difference?? set it to false anyway upon your recommendation.

i managed to find a short workaround by declaring
 Public frmR as frmMQ
in the bas module instead of in frmMain, but that will not work for multiple frmMQs and as well as a dynamic number of other child forms using frmGSMControl.

should i go with an array to hold references to instances of multiple forms, or is there a simple way of keeping track ?

code example or reference would be much appreciated
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7124190
As I said, you can loop throug the forms collection, and using a common property you can determine if you found the frmMQ...

Here how I do such things:

dim f as form
dim fMQ as frmMQ
for each f in Forms
  if f.SomeProperty = SomeValue then
    set fMQ = f
  end if
next

if fMQ is nothing then
  'you found no relevant form frMQ...
  set fMQ = new frmMQ
  fMQ.<InitForm>...
end if

fMQ.<LoadData> ...

etc
CHeers
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:JooZ
ID: 7124219
thanks for the help, theres still a few kinks to work out with the application and referencing, specifically: figuring out how to dim each instance of the same form with a unique property (use the caption?).

for example , say if i used frm.caption (?) as the check for f.someproperty in your example above, how would i *dynamically* dim *each* form instance without using an array and setting the frm.caption to a unique identifier? (the real problem, not so much the finding of the right form)

gahh.. i'm zombified and repeating myself. heh.

or is Forms already an array of type frmMQ?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 7124224
Forms is an existing collection you can use as is.

I typically add 2 properties to my forms:
FormType as string
FormKey as string

I would choose FormType to be "MQ" for the frmMQ (on Form_Load), and FormKey would represent a key information (normally set in the <LoadData> sub.

CHeers
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 7124515
Here is an example:

'In Module:
Sub main()
Load MDIForm1
End Sub

Public Sub test_text(frm As Form, smsg As String)
frm.Text1 = smsg
End Sub

'In the MDIForm:
Private Sub MDIForm_Load()
Load Form1
Load Form2
Form1.Show vbModeless
Form2.Show vbModeless
End Sub

'On the child form1, 2 buttons & text1:
Private Sub Command1_Click()
Call test_text(Me, "Hello")
End Sub

Private Sub Command2_Click()
Call test_text(Form2, "Hello from form1")
End Sub

'On child form2, a text1 textbox...
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 7124520
PS: Use the TAG property of the child forms give each a unique ID if there are multiple instances...
0
 
LVL 2

Expert Comment

by:nahumd
ID: 7124651
Anyway, when you asked the question, you knew which form you wanted to choose , which means that you already have a property or anything that uniquely distinguishes one form from the others.
0
 

Author Comment

by:JooZ
ID: 7126144
excellent stuff :)
have got the problems worked out already, tho i still need to multi-thread the processes in each form. *its a fairly complex app, an SMS gateway, actually. (yes it can be done in VB) Will tinker around a bit and see if the algorithms work after i have multi-threaded the processes.

angelIII will get the points anyway for having provided me with great guidance.
 
after i have accepted an answer, is it possible for other people to post comments without having to pay points to view the question ?

does anyone have any comments on their multi-threading experiences or methodologies ?

also, if anyone is interested in the SMS gateway code, i'll be glad to share development ideas and code snippets. just drop me an email :)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7126156
Hi,

All those that have commented will see the q for free, others would need to pay 20points (once). users with the KnowledgePro profile will see all q for free.

VB6+multithreaded: never done that...

CHeers
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question