hey ppl, i know this is aa really daft Q, but i only started using vb.net this yr and im not that gud at it!

basically i wana know how to go from one form to another using a button, wud it just be sumthin as simple as:

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

btnSearch = frmSearch

endSub

Dani AI

Generated

Short summary and corrections to the thread: the line in the original post tries to assign a control rather than open a form. is on the right track — a form is a class, so an instance must be created and shown. 's remark about using "As New Form" is misleading: that would create the base Form type, not the specific form class (e.g., frmSearch).

A safe modal pattern (passes data in, reads a result, and ensures disposal):

Using dlg As New frmSearch()
    dlg.InitialQuery = txtQuery.Text
    If dlg.ShowDialog(Me) = DialogResult.OK Then
        txtResult.Text = dlg.SelectedValue
    End If
End Using

A modeless approach (keeps both windows open) and an option to hide the caller:

Dim searchWin As New frmSearch()
searchWin.Owner = Me
searchWin.Show()
Me.Hide()   ' optional: hide the current form instead of closing it

Practical notes and troubleshooting:

  • ShowDialog blocks the caller until the dialog closes; Show does not. Choose modal when the user must finish the task first.
  • Default VB.NET form instances (calling frmSearch.Show() without New) exist and are convenient, but can hide lifetime/state issues — explicit instances are clearer for learning.
  • Use Using or call Dispose() after modal dialogs to avoid leaks. For modeless forms, manage lifetime yourself.
  • Avoid naming variables the same as form classes (that causes "ambiguous" errors). All form creation and UI calls must run on the UI thread.
  • If closing the startup form causes the app to exit, consider hiding it or using an ApplicationContext to control application lifetime.

Reference: asked the original question; ’s suggestion is essentially correct; ’s “as New Form” advice should not be used for creating a specific form instance.

No, you will need to create an object variable for the form you wish to open.

Somthing like this under the button sub should work:

Dim objNewForm as New NewForm()
objNewForm.ShowDialog()

Chester

Adding to what cpopham said, make a subroutine for one of your buttons like this:

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

objNewForm.ShowDialog()

End Sub

Also make sure you put Dim objNewForm as New Form somewhere near the top. It should be "as New Form" and not "as New NewForm()"

That's in my version at least.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.