Solved

MDI toolbar needs to send message to child!

Posted on 1998-04-18
10
330 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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 200 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

809 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