Access databases and VB

Moderators: Gogi
Number of threads: 762
Number of posts: 1591

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Query attached to button to display a new window for database search Posted by Anthei on 12 May 2012 at 2:24 PM
I'm creating an inventory application. It has a combo box for rooms, and I'm trying to code the "Display" button. I got it to open up the database in a new window, but I'm trying to get it to come up and search the database with the cmbRooms.Text information and compare it to the room data in the records. I'm wondering if that's even possible? If so, am I able to do it from the Main Form, or do I have to modify the code in the Database form instead, or in addition to the Main Form's code?

Here's the Main Form's Display button code so far. When I run the application and select a room, and click "Display", it comes up with an error on this line:
Call frmDatabase.Show(record)
I've tried to get it to work, but I can't find an example or help on how to do it anywhere!

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
	    Dim frmDatabase As New Database()
	    Dim record = From inventory In inventoryDataSet.Inventory
	                 Where (inventory.room Like cmbRooms.Text)
	                 Order By inventory.ID
	                 Select inventory
	 
	    'If textbox for cmbRooms is occupied, and holds the value "All"
	    'Then show the whole database
	    If cmbRooms.Text > "0" AndAlso cmbRooms.Text = "All" Then
	        frmDatabase.Show()
	    ElseIf cmbRooms.Text > "0" Then
	        'if textbox occupied, search database using query
	        Call frmDatabase.Show(record)
	 
	    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


Here's my code for the database form:

Public Class Database

    Private Sub InventoryBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InventoryBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.InventoryBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.InventoryDataSet)

    End Sub

    Private Sub Database_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'InventoryDataSet.Inventory' table. You can move, or remove it, as needed.
        Me.InventoryTableAdapter.Fill(Me.InventoryDataSet.Inventory)

    End Sub
End Class




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.