execute public sub on other form

S

Sven

i have 2 forms:

form1 with 1 button

Dim f As New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

f.Show()

End Sub

Public Sub sven()

MsgBox("dd")

End Sub



form2 with 1 button

Dim f As Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

f.sven()

Me.Hide()

End Sub



Why does this not work? how can I execute sven by clicking button1 on form2?
 
H

Herfried K. Wagner [MVP]

* "Sven said:
i have 2 forms:

form1 with 1 button

Dim f As New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

f.Show()

End Sub

Public Sub sven()

MsgBox("dd")

End Sub

Add a public property of type 'Form1' to Form2 and pass a reference to
your instance of 'Form1' to 'Form2' by setting this property to 'Me' in
'Form1'. Then you can access the instance of 'Form1' from 'Form2'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top