VB2019 VB2017 VB2015 VB2013 VB2012 VB2010 VB2008 VB6 VB Sample Codes 中文VB About Us

Inventory Management System



All businesses involve inventory and need to manage it efficiently to ensure smooth running of the business activities and profitability. To manage inventory efficiently, business owners need to develop a good inventory management system . Building a sound inventory management system usually incur high cost. Fortunately, we can use Visual Basic 6 to build an inventory management system which does not require big capital, you can do it at home.

In Visual Basic 6, there are a number of built-in database management tools which we can use to manage the data.To start building a good inventory system, we need to have a good planning. First of all, you have to sit down with your client to get detail information about his or her businesses and establish the kind of system he or she wants. For example, you need to know what types of goods they are dealing with, the turn-over volumes, cost prices, selling prices and more. Besides that, you need to know what kind of documents the system needs to deal with like invoices, delivery orders and more.

After getting all the necessary information from your client, you can then start to build a database. Based on the number and types of products, you need to decide what are the variables or fields needed to be included in the database's tables.

The figure below shows the inventory management system developed by us using Visual Basic 6.

We shall use a hypothetical case to illustrate how to build an inventory system as shown above. Let's say our client is dealing with electrical goods. To design the database tables, we need to determine how many tables are needed. In order to keep things  simple, we shall limit to two tables in our example. The first table shall be used to store the data of the inventory or stock in hand. The second table shall be used to record stocks coming in and stocks going out.


The first table shall comprise the following fields:


The second table shall comprise the following fields:

In our example, we named the first table Inventory and the second table Stock .After designing the tables, we can then proceed to create a database that comprises the two tables. We can either use Microsoft Access to create the database or we can use the built-in Visual Data Manager in Visual Basic 6. Visual Data Manager can be used to create tables, add new data as well as edit data. Besides that, it can be used to modify table structure. To learn how to create database using Visual Data Manager, follow the link below:

http://www.vbtutor.net/index.php/creating-database-using-visual-data-manager/

 

Step 2 : Inserting controls into Form

The next step is to insert some relevant controls into the form for displaying and manipulating the data of the database. The controls to be inserted are ADO controls, DataGrid controls, FlexGrid control and various command buttons. DataGrid controls and FlexGrid controls are used to display and store the data from the database tables. On the other hand, ADO is used to manipulate the database such as connecting the DataGrid and FleGrid to the database.

. As ADO is ActiveX-based, it can work in different platforms (different computer systems) and different programming languages. Besides, it can access many different kinds of data such as data displayed in the Internet browsers, email text and even graphics other than the usual relational and non relational database information.

To be able to use ADO data control, you need to insert it into the toolbox. To do this, simply press Ctrl+T to open the components dialog box and select Microsoft ActiveX Data Control 6. After this, you can proceed to build your ADO-based VB database applications.

In our example, we insert two ADO controls and name them AdoInventory and AdoStock respectively. The first is to deal with data in the Inventory table and the second is to deal with data in the Stock table. We also insert two DataGrid controls and named them DataInventory and DataStock respectively. They are use to display the data to the user. Besides, we insert one FlexiGrid control to store the data and also to print out the data by connecting it to MS Excel spreadsheet.

Step 3 : Writing the Code

After inserting the necessary controls, it is time to write code to coordinate the controls and to manipulate the data. The first most important code for our program is to connect the ADO controls to the database when the form is loaded. The code is as shown below:

Private Sub Form_Load()
'To connect AdoInventory to MS Access database inventory_br.mdb
AdoInventory.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Voon Kiong Liew\My Documents\Liew Folder\Bunga Raya\inventory_br.mdb;Persist Security Info=False"
AdoInventory.RecordSource = "SELECT * FROM Inventory"
AdoInventory.Refresh
Set DataInventory.DataSource = AdoInventory

'To connect AdoStock to MS Access database inventory_br.mdb
AdoStock.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Voon Kiong Liew\My Documents\Liew Folder\Bunga Raya\inventory_br.mdb;Persist Security Info=False"
AdoStock.RecordSource = "SELECT * FROM Stock"
AdoStock.Refresh
Set DataStock.DataSource = AdoStock

Notice that we use SQL syntax  SELECT * FROM to select all the data from the Inventory table and the stock table. SQL is a powerful language that is used to manipulate databases.

The next code is to let user enter data into the DataInventory table and double click to update the data as well as to calculate the total cost. It also add brands and categories into the brand combo box and the category combo box respectively .The code is as follows:

Private Sub DataInventory_DblClick()
If AdoInventory.Recordset.Fields("CPU") <> "" Then

Dim TotalCost As Integer
TotalCost = Val(AdoInventory.Recordset.Fields("CPU")) * Val(AdoInventory.Recordset.Fields("Stock"))
AdoInventory.Recordset.Fields("TCost") = Str(TotalCost)
Else

AdoInventory.Recordset.Fields("TCost") = ""
End If
'To load all brands into comboBrand
'To load all Categories into comboCategory

Do Until AdoInventory.Recordset.EOF
ReDim B(i), C(j) As String

B(i) = AdoInventory.Recordset.Fields("Brand")
C(j) = AdoInventory.Recordset.Fields("Category")

ComboBrand.AddItem B(i)
ComboCategory.AddItem C(j)

AdoInventory.Recordset.MoveNext

Loop
AdoInventory.Recordset.MoveFirst
End Sub
 

We also need to write the code to search for the items once they are entered into the inventory table. The code is as follows:

'Search for items using SQL query

Dim SearchString1, SearchString2 As String
SearchString1 = ComboBrand.Text
SearchString2 = ComboCategory.Text

If ComboBrand.Text <> "All Brands" And ComboCategory.Text <> "All Categories" Then

AdoInventory.RecordSource = "SELECT * FROM Inventory WHERE Brand='" & SearchString1 & "' and Category='" & SearchString2 & "'"

ElseIf ComboBrand.Text = "All Brands" And ComboCategory.Text <> "All Categories" Then

AdoInventory.RecordSource = "SELECT * FROM Inventory WHERE Category='" & SearchString2 & "'"

ElseIf ComboBrand.Text <> "All Brands" And ComboCategory.Text = "All Categories" Then
AdoInventory.RecordSource = "SELECT * FROM Inventory WHERE Brand='" & SearchString1 & "'"

ElseIf ComboBrand.Text = "All Brands" And ComboCategory.Text = "All Categories" Then

AdoInventory.RecordSource = "SELECT * FROM Inventory"

End If
AdoInventory.Refresh

Next, we write code to entering new item in DataStock table. The code is as follows:

'To add items to Ado Stock
AdoStock.Recordset.AddNew
AdoStock.Recordset.Fields("Date") = Format(Date, "dd/mm/yyyy")
AdoStock.Recordset.Fields("Category") = AdoInventory.Recordset.Fields("Category")
AdoStock.Recordset.Fields("Brand") = AdoInventory.Recordset.Fields("Brand")
AdoStock.Recordset.Fields("Item Description") = AdoInventory.Recordset.Fields("Item Description")
AdoStock.Recordset.Fields("Model Number") = AdoInventory.Recordset.Fields("Model Number")
AdoStock.Recordset.Fields("CPU") = AdoInventory.Recordset.Fields("CPU")
AdoStock.Recordset.Update

*Please note that AddNew is to allow adding new data and Update is to save data.
 

View Full Code


 


Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy