?
Solved

MDI toolbar needs to send message to child!

Posted on 1998-04-18
10
Medium Priority
?
349 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
Technology Partners: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

752 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