Solved

MDI toolbar needs to send message to child!

Posted on 1998-04-18
10
318 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now