Firstly, you can't pass random stuff to the Form's Show method so that's not the way to go.
What you should probably be doing is using the Form's Constructor to pass the relevant information to the Database form.
The big question is what to send to the Database form? The best answer to this question would depend on how you might want to extend this further, but a simple example would pass the SQL Query that the database form has to run. That way you could have many other uses for the database form and you just have to send it the query to run. Also, all the Database form has to do is run the query that it is given and display the results.
Firstly there's the constructor for the Database form. Constructors are the Sub New for a class. Forms are a bit different that other classes in that a Form's Sub New must have InitializeComponent called in it. If you don't have InitializeComponent in a Form's Sub New then the IDE will moan about an error and won't compile the project.
So, The Database Form's class now includes...
Code:
Public Class Database
' A private variable to store the query in
private queryToRun as string
Public Sub New(byval query as String)
' This call is required by the Windows Form Designer.
InitializeComponent
' Save the query to run
me.queryToRun = query
End Sub
End Class
Then, in the Form's load event, you'll use the query to set up a Command to run and display.
Using the Database class that now has a constructor, the following line in your code won't work...
Code:
Dim frmDatabase As New Database()
... because you can't create a database form without passing it a query to run (i.e. there is no Sub New without any parameters). That's a good thing because in the Database form we don't have to worry about whether a query has been passed or not. It must have been because the form couldn't have been created without one.
So, the code to use it would now look something like...
Code:
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
'displays the Database window with a search query of the specified room
'Declarations
' No New here now in the declaration of the form. It will be created later when the query is known
Dim frmDatabase As Database()
'If textbox for cmbRooms is occupied, and holds the value "All"
'Then show the whole database
If cmbRooms.Text = "All" Then
frmDatabase = New Database("SELECT * FROM inventory")
frmDatabase.Show
ElseIf cmbRooms.Text > "0" Then
frmDatabase = New Database("SELECT * FROM inventory WHERE room LIKE '%'" & cmbRooms.Text & "'%'")
frmDatabase.Show
Else
'if textbox empty, view error
MessageBox.Show("Please select a room or type 'All' in the Room text field to view all entries.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End If
End Sub