Reference a sub on another form

Reggie213

Member
Joined
May 24, 2012
Messages
12
Programming Experience
Beginner
Hi,

So this is driving me half insane.

I have an mdi form setup so here is my problem

mdiParent : mdiMain
mdichild : frmData
Sub on frmData : Public Sub GenerateData()

Form : popForm

I open the parent then the child. In the menustrip on the parent I have an option that opens popForm using popForm.showdialog()

On popForm there is a button that when clicked I want it to run a Public sub on frmData (the child form)

Intellisense doesnt even pickup that form when I start typing it.. and just typing in the following

frmData.Generatedata()

...comes up with the error frmMaindata is not declared.

Thanks

Reg

vb.net 2.0, winform app, visual studio 2010
 
Hi,

On the load event of the parent I do the following

Dim frm As New Form()

frm.MdiParent = Me
frm.FormBorderStyle = FormBorderStyle.None
frm.ControlBox = False
frm.MinimizeBox = False
frm.MaximizeBox = False
frm.Show()
frm.Dock = DockStyle.Fill


Me.WindowState = FormWindowState.Maximized
If blnActive = IsOpen("frmmaindata") Then
Dim mainWindow As New lstViewCat


mainWindow.MdiParent = Me
mainWindow.StartPosition = FormStartPosition.CenterScreen
mainWindow.Show()
mainWindow.WindowState = FormWindowState.Maximized
End If

The popForm triggers from the toolbar on the parent

Private Sub OptionsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OptionsToolStripMenuItem.Click
popForm.ShowDialog()
End Sub
 
In simple terms.. the child form shows a dataset that is generated/refreshed using a public sub called generatedata()

the popForm offers the ability to change some of the criteria, so I was just trying to call the refresh after the user hits save on the popForm!
 
I don't see any mention of frmMainData in there either, other than as a String passed to IsOpen. That doesn't show how you're opening the form you're trying to reference.
 
Please see isopen function.

Thanks

Private Function IsOpen(ByVal nameForm As String) As Boolean Dim childfrm As Form
Dim strName As String
Dim intLastIndex As Integer


For Each childfrm In Me.MdiChildren
strName = childfrm.GetType.ToString
intLastIndex = strName.LastIndexOf(".")
strName = Mid(strName, intLastIndex + 2, Len(strName) - intLastIndex)
If LCase(strName) = LCase(nameForm) Then
childfrm.BringToFront()
Return True
End If
Next
Return False




End Function
 
Although you might not think you have provided me the answer you have...

Originally this form was called lstViewCat.. I renamed it but didn't change the class name so at the top of the code it still stated Public Class lstViewCat

DOH!!!

Now ive renamed that class it all shows up in intellisense and allows me to reference the public sub

frmData.Generatedata()

And that should also explain how

If blnActive = IsOpen("frmdata") Then
Dim mainWindow As New frmData


mainWindow.MdiParent = Me
mainWindow.StartPosition = FormStartPosition.CenterScreen
mainWindow.Show()
mainWindow.WindowState = FormWindowState.Maximized
End If

Opens up my form!
 
Back
Top