Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

MDI toolbar needs to send message to child!

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
tedwilson
Asked:
tedwilson
  • 5
  • 3
  • 2
1 Solution
 
RolandKoehrsenCommented:
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
 
tedwilsonAuthor Commented:
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
 
RolandKoehrsenCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
kamallCommented:
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
 
RolandKoehrsenCommented:
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
 
kamallCommented:
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
 
tedwilsonAuthor Commented:
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
 
tedwilsonAuthor Commented:
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
 
RolandKoehrsenCommented:
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
 
RolandKoehrsenCommented:
This works out fine. I was trying to avoid public variables, but it may be the only way.

Thanks!

0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now