Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MDI toolbar needs to send message to child!

Posted on 1998-04-18
10
Medium Priority
?
357 Views
Last Modified: 2011-10-03
Say you have an MDI form with about 100 different children (not open all at once). The MDI parent has a toolbar and the buttons include: delete, cancel, and search that operate on records not text. Unlike buttons such as cut/copy/paste for which you can write generic code, these buttons will behave differently based upon which child is active. I need to send a message from the MDI parent toolbar to the child form telling it that the Delete button was pressed (for example.) At that point the child would handle it's specialized code from there.

What is the best way to do this?
0
Comment
Question by:tedwilson
[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
  • 5
  • 3
  • 2
10 Comments
 

Expert Comment

by:RolandKoehrsen
ID: 1425005
Have you thought about daclaring a public sub in each MDI child like

public sub tbButton1Pressed ()
...
end sub

and calling it from the toolbar like this:
on error resume next
call me.ActiveForm.tbButton1Pressed
0
 

Author Comment

by:tedwilson
ID: 1425006
This is why the 'on error resume next' is there. If the sub doesn't exist, no error will occur... I have tested it, I think my answer is worth being graded... ;-)
Roland
0
 

Expert Comment

by:RolandKoehrsen
ID: 1425007
tedwilson,
You can just put this generic procedure on all child forms but simply without any code in the child forms where nothing really is to be done.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:kamall
ID: 1425008
I don't know if you can still grade my answer although you have rejected it before. If You whish to accept it, you might re-open the question and I might repeat my answer...

Roland
0
 

Expert Comment

by:RolandKoehrsen
ID: 1425009
tedwilson,
I locked the qusetion because I was posting an answer but I got an error at that moment probably because the question was just been locked.
However, to be fair, I think that RolandKoehrsen should get the points if his answer is satisfactory. In that case, you can reject my answer and award him the points.
Regards to all.

0
 
LVL 7

Expert Comment

by:kamall
ID: 1425010
kamall and RolandKoehrsen both answered at exactly 4:09pm. To be fair I will go ahead and try to pass it on Roland.

Thanks to both of you!


0
 

Author Comment

by:tedwilson
ID: 1425011
It works as advertised. However, on a related note:
I am calling this procedure...

Public Sub MyLoad(MyAcctID As String, MyAcctName As String)
    frmAcctNotes.Show
End Sub

...in order to pass the variables to the current form.
However when the form loads...

Private Sub Form_Load()
    Me.Caption = "Account Notes: " & MyAcctID & "-" & MyAcctName

...MyAcctID and MyAcctName are filled with chr$(0)

What's wrong here? I even tried passing different names in MyLoad and assigning MyAcctID/MyAcctName to those variables with the same result.

Thanks,
ted.wilson@bigfoot.com


0
 

Author Comment

by:tedwilson
ID: 1425012
The problem is that MyAcctID and MyAcctName aren't public, and probably shouldn't


You might either do this: (change the form's caption from where it's loaded)

       Public Sub MyLoad(MyAcctID As String, MyAcctName As String)
           frmAcctNotes.Show
           frmAcctNotes.caption="Account Notes: " & MyAcctID & "-" & MyAcctName
       End Sub

or this: (submit the two strings to the form)

  -  in frmAccNotes (or its class form):
   
    public currentAcctID as string
    public currentAcctID as string

    Private Sub Form_Load()
           Me.Caption = "Account Notes: " & currentAcctID & "-" & currentAcctName
    ...
    end sub
  -  and in the other form:

      Public Sub MyLoad(MyAcctID As String, MyAcctName As String)
           frmAcctNotes.currentAcctID = MyAcctID
           frmAcctNotes.currentAcctName = MyAcctName
           frmAcctNotes.Show
      End Sub

the second version only works if the frmAcctNotes is not loaded before shown (after it's hidden and shown again, naturally the form_load event doesn't occur)
If it's hidden before shown and you still whish to change the caption you should not put the me.caption=... in "private sub form_load ()" but in a
"public sub change_caption (byval MyAcctID as string, byval MyAcctName as string)" in frmAcctNotes
You need't declare these two in the form in this case, but after
frmAcctNotes.show
you can call this procedure with
call frmAcctNotes (MyAcctID, MyAcctName)


Roland

(Do I now get the points for these TWO answers? ;-)
0
 

Accepted Solution

by:
RolandKoehrsen earned 800 total points
ID: 1425013
Ted Wilson,... Pretty messed up everything here...
My right answer to the first question got rejected, now another question in a comment, my second answer probably gets accepted but doesn't refer to the topic... Think of other users later that will look up this Q&A - how shall they see through this?

...anyway, as long as I get the points ;-)
0
 

Expert Comment

by:RolandKoehrsen
ID: 1425014
This works out fine. I was trying to avoid public variables, but it may be the only way.

Thanks!

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 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