Results 1 to 19 of 19

Thread: MDI problem ! HELPPPPP

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108

    Unhappy MDI problem ! HELPPPPP

    i have a problem with the MDI

    i have the main menu and i have set the main menu event with MainMenu_Activated

    inside that i have a if statement called

    If newclientinfo.CheckSaving1 = 1 Then

    MenuItem14.Enabled = True

    Else

    MenuItem14.Enabled = False

    End If

    End sub

    and in the child form call newclientinfo when the newclientinfo _closed i have a SQL command

    select the client if the datareader read than i set the CheckSaving1 to 1

    why it wont work ??? the CheckSaving1 is set to Public

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    What is newclientinfo?
    For a quick answer, I'd suggest avoiding MDI forms. They're a pain.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    the newclientinfo is a form and is a child of the main menu

    i wanna use a MDI format to develop a system

    so please help

  4. #4
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    MDI forms rule

    I dont really understand what your trying to do but

    i guess your problem is the fact your calling your perant mdi from your child form and it errors this is most likely becuase child forms speaking to perants ant all that

    If you add a module to your solution then add a public variable of

    pulbic FrmPerant as "what ever the perant is called"

    then from the child form to access properties of the perant just use

    frmPerant.WHATEVER

    modules are global to the entire solution they do not need instanciating there they can be called when ever how ever......

    hope it helps
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  5. #5
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Carl, you are correct, MDI forms do rule, now to try and help ninjaX.

    How are you instantiating your form?

    And is the name of the actual form newclientinfo or is that the instance name?

    The problem with trying to reference controls on a form is that if you come from VB6 or earlier, then by just referencing a form by it's actual name worked fine, that is not true in VB7.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    i got one simple MDI question

    i can use what event to keep track what the child has done, example my parent window will continue keep track when the form is activate i have try the activated event before but no use.

    example

    i have a child form call newclient and parent is mainmenu

    after the newclient click at the save button, some of the main menu function will set the enabled to true can i know how to do that ????

    coz some of my function cannot be use if the user dont click at the newclient save button

  7. #7
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Create a public method in your MDI parent form and have the child form call that method as the last call in the save button click event.
    VB Code:
    1. Private myParent As New mainmenu
    2. Private Sub btnSave_Click()
    3.     'Other code goes here
    4.     myParent.EnableControls
    5. End Sub

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    is it create at the parent form or inside the child form ???

    why the myParent.EnabledControls cannot use one ?

  9. #9
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Well then

    In your child form, declare a public event like "Saved" and raise the event to all listeners (should only be your MDI container)

    VB Code:
    1. Public Event Saved
    2. Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
    3.     'Other code goes here...
    4.     RaiseEvent Saved
    5. End Sub

    And in your MDI container form declare your child form withevents and code the event handler

    VB Code:
    1. Private WithEvents ChildNew As frmChild
    2. Private Sub ChildNew_Complete() Handles ChildNew.Complete
    3.     MessageBox.Show("It worked")
    4. End Sub

    This should do the trick nicely . . . it works on my machine

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    Sorry CyberHawke

    Private WithEvents ChildNew As frmChild
    Private Sub ChildNew_Complete() Handles ChildNew.Complete
    MessageBox.Show("It worked")
    End Sub




    .Complete Wont Work

  11. #11
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Sorry, my bad, that's what I get for editing my code in this window.
    VB Code:
    1. Public Event Saved
    2. Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
    3.     'Other code goes here...
    4.     RaiseEvent Saved
    5. End Sub

    VB Code:
    1. Private WithEvents ChildNew As frmChild
    2. Private Sub ChildNew_Saved() Handles ChildNew.Saved
    3.     MessageBox.Show("It worked")
    4. End Sub
    Whadayamean it doesn't work....
    It works fine on my machine!

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    Sorry CyberHawke

    Donno why my coding cannot work with the code

    ai ~~


    Public Event Saved
    Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
    'Other code goes here...
    RaiseEvent Saved
    End Sub

    this one i put it in my child called newclient

    Private WithEvents ChildNew As frmChild
    Private Sub ChildNew_Saved() Handles ChildNew.Saved
    MessageBox.Show("It worked")
    End Sub

    this one i put in my parent form called main menu

    but after i click the save button it wont work for me

    is it my code for problem ??

  13. #13
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    It looks correct, I guess you should paste the code out of your actual module here, because this works fine for me
    Whadayamean it doesn't work....
    It works fine on my machine!

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    the parent for is call mainmenu the code is like below:

    Dim newclientinfo As New newclientinfo
    Private WithEvents ChildNew As newclientinfo

    Private Sub MenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem13.Click

    If Check = 0 Then

    doccode.ShowDialog()
    newclientinfo = New NewClientInfo

    If doccode.CheckCancel <> 1 Then

    newclientinfo.code_TextBox.Text = doccode.DocCode_TextBox.Text
    TempDocCode = doccode.DocCode_TextBox.Text
    newclientinfo.Show()
    newclientinfo.MdiParent = Me
    Check += 1

    End If

    If doccode.CheckCancel = 1 Then

    doccode.CheckCancel = 0
    TempDocCode = 0

    End If

    Else

    Dim mainmenu As New MainMenu
    mainmenu.Show()

    End If

    Private Sub ChildNew_Saved() Handles ChildNew.Saved
    MessageBox.Show("It worked")
    End Sub


    ===============================================
    the code below is for my new client form

    Public Event Saved()

    Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click

    Dim mainmenu As New MainMenu
    Dim IntSave As Integer
    Dim ClientName As String

    IntSave = MsgBox("Do You Want To Save Your Data ?", MsgBoxStyle.OKCancel, "Save")

    If IntSave = DialogResult.OK Then

    Try

    OleDbConnection1.Open()
    '*********************************************
    Dim DataReader As OleDb.OleDbDataReader
    OleDbDataAdapter1.SelectCommand.CommandText = "SELECT Client From Client Where Client = '" & ClientName_TextBox.Text & "' And Code = '" & code_TextBox.Text & "' "

    DataReader = OleDbDataAdapter1.SelectCommand.ExecuteReader

    If DataReader.Read Then

    MessageBox.Show("Client Name Already Been Save. Thank You", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)

    Else
    DataReader.Close()
    SaveClientInfo()
    CheckSaving = 1
    RaiseEvent Saved()

    End If

    Catch ex As Exception

    MsgBox(ex.ToString())

    Finally

    OleDbConnection1.Close()

    End Try

    If IntSave = DialogResult.Cancel Then

    MessageBox.Show("Data Not Save")
    CheckSaving = 0

    End If

    End If

    End Sub

    is it enough ?
    thanx for helping me

  15. #15
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    two things, first, can you send me your code?

    second, if you are going to paste code here, please use the vb format tags, it makes it much easier to read thanks
    Whadayamean it doesn't work....
    It works fine on my machine!

  16. #16
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Remove this line:
    Dim newclientinfo As New newclientinfo

    Change this line:
    newclientinfo = New NewClientInfo
    to:
    ChildNew = New newclientinfo

    Replace all other references to newclientinfo to ChildNew

    From what I am reading here, that should fix it.
    Whadayamean it doesn't work....
    It works fine on my machine!

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    thanx, CyberHawke the code is working now !!!
    thanx ~

    but now i got another problem, do mind to teach me ??

    the problem is when i open one parent form and the user click at the new client to try to input another client information

    example

    form 1 and when i click at new client to let user to input again that is form 2 but when i close the form 1 the form 2 will continue close it hwo can i avoid the form 2 close ????

    i have us the coding below to create a new form

    If Check = 0 Then

    Do my things here

    Else

    Dim mainmenu As New MainMenu
    mainmenu.Show()

    End If

    can CyberHawke know what i mean ??

  18. #18
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Ok, if I understand you correctly, you have two forms, your main form (mainmenu) and your client form newclientinfo, now when your user creates an instance of your newclientinfo form from the mainmenu form and then closes the mainmenu form, the newclientinfo form goes away also. Is that correct?
    Whadayamean it doesn't work....
    It works fine on my machine!

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    108
    sorry, actually i have create 2 main form

    If Check = 0 Then

    Do my things here

    Else

    Dim mainmenu As New MainMenu
    mainmenu.Show()

    End If

    i use the check to detect is the user is click at the new client this menu item or not if not it will display the new client

    if yes it will help me to create another parent and when i have 2 parent is open, i call it parent 1 and parent 2 if i close the parent 1 the parent 2 will also close it, it is possible to make the 2 parent independent like the microsoft word ???

    and the second problem is that i have open a form and the form have a document code textbox call 123, and when user is try to open the form document code 123 and the system will help me to detect is the form document code is open or not ?????

    thank you very much

    sorry to disturbing you again
    Last edited by ninjaX; Jul 1st, 2004 at 03:35 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width