Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

Browse Topics

- Getting started
- Data Types
- Modules
- Operators in VB6
- VB6 Variable
- VB6 Procedures
- VB6 Control Structures
- Loops in VB6
- VB6 Exit Do & With End With
- Arrays in VB6
- User-Defined Data Types
- VB6 Constants
-
VB6 Built-in Functions
- Date and Time in VB6
- VB6 Controls
- TextBox Control
- ComboBox & OptionButton
- Label & Frame
- PictureBox & ImageBox
- Timer Control
- ListBox & ComboBox
- VB6 ScrollBar
- Control Arrays in VB6
- Files controls in VB6
- VB6 CheckBox
- Forms in VB6
- Menus in VB6
- MDI Form in VB6
- InputBox
- MessageBox
- Mouse events
- Mouse Move
- Error Handling
-
Error Handling (2)
-
VB6 Database

You are here: Visual Basic > VB6 (Beginners Tutorial)

Tutorial Main Page | Previous Page | Contents | Next Page

Exercise - Home Inventory Database

Design and develop an application that manages a home inventory database. Add the option of obtaining a printed list of your inventoried property.

My Solution:

Database Design:

The first step is to design a database using Data Manager (or Access). My database is a single table (named MYSTUFF). Its specifications are:

This database is saved as file HomeInv.mdb. Create a data link to your database. The link is saved as HomeInv.udl.

Report Design:

The second step is to use the Data Environment and Data Report designers to setup how you want the printed home inventory to appear. Use your discretion here. My final report design is saved in denHomeInv and rptHomeInv. We will access this report from our Visual Basic application. My Data Report design looks like this:

Project Design:

Form:

Properties:

Form frmHome:
BorderStyle = 1 - Fixed Single
Caption = Home Inventory

CommandButton cmdExit:
Caption = E&xit

ADO Data Control dtaHome:
Caption = Book Titles
ConnectionString = HomeInv.udl (in whatever folder you saved it in -
select, don’t type)
RecordSource = SELECT * FROM MyStuff
Visible = False

CommandButton cmdShow:
Caption = Show &Report

CommandButton cmdPrevious:
Caption = &Previous Item

CommandButton cmdNext:
Caption = &Next Item

CommandButton cmdDelete:
Caption = &Delete Item

CommandButton cmdAdd:
Caption = &Add Item

TextBox txtLocation:
DataField = Location
DataSource = dtaHome
FontName = MS Sans Serif
FontSize = 9.75
MaxLength = 40

TextBox txtValue:
DataField = New Value
DataSource = dtaHome
FontName = MS Sans Serif
FontSize = 9.75

TextBox txtDate:
DataField = Date Purchased
DataSource = dtaHome
FontName = MS Sans Serif
FontSize = 9.75
MaxLength = 20

TextBox txtSerial:
DataField = Serial Number
DataSource = dtaHome
FontName = MS Sans Serif
FontSize = 9.75
MaxLength = 20

TextBox txtItem:
DataField = Item
DataSource = dtaHome
FontName = MS Sans Serif
FontSize = 9.75
MaxLength = 40

Label Label5:
Caption = Location
FontName = Times New Roman
FontSize = 12

Label Label4:
Caption = New Value
FontName = Times New Roman
FontSize = 12

Label Label3:
Caption = Purchase Date
FontName = Times New Roman
FontSize = 12

Label Label2:
Caption = Serial Number
FontName = Times New Roman
FontSize = 12

Label Label1:
Caption = Item
FontName = Times New Roman
FontSize = 12

Code:

General Declarations:

Option Explicit

cmdAdd Click Event:
Private Sub cmdAdd_Click()
'Add new item to database
dtaHome.Recordset.AddNew
txtItem.SetFocus
End Sub

cmdDelete Click Event:
Private Sub cmdDelete_Click()
'Delete item from database
Dim Rvalue As Integer
Rvalue = MsgBox("Are you sure you want to delete this item?", vbQuestion + vbYesNo, "Delete Item")
If Rvalue = vbNo Then Exit Sub
dtaHome.Recordset.Delete
dtaHome.Recordset.MoveNext
If dtaHome.Recordset.EOF Then
If dtaHome.Recordset.BOF Then
MsgBox "You must add an item.", vbOKOnly + vbInformation, "Empty Database"
Call cmdAdd_Click
Else
dtaHome.Recordset.MoveFirst
End If
End If
txtItem.SetFocus
End Sub

cmdExit Click Event:
Private Sub cmdExit_Click()
End
End Sub


cmdNext Click Event:
Private Sub cmdNext_Click()
'Move to next item - if at end-of-file, backup one item
dtaHome.Recordset.MoveNext
If dtaHome.Recordset.EOF Then dtaHome.Recordset.MovePrevious
txtItem.SetFocus
End Sub

cmdPrevious Click Event:
Private Sub cmdPrevious_Click()
'Move to previous item - if at beginning-of-file, go down one item
dtaHome.Recordset.MovePrevious
If dtaHome.Recordset.BOF Then dtaHome.Recordset.MoveNext
txtItem.SetFocus
End Sub

cmdShow Click Event:
Private Sub cmdShow_Click()
rptHomeInv.Show
End Sub


  

Tutorial Main Page | Previous Page | Contents | Next Page

   

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved