100% found this document useful (2 votes)
78 views5 pages

Database Design:: Visual Basic

The document describes the design of a home inventory database and application in Microsoft Access. It involves: 1) Creating a single table database with fields to store item details and saving it. 2) Designing a report in the Data Report designer to display the inventory. 3) Building a form in the Visual Basic editor to allow adding, editing, deleting and viewing items with navigation buttons and text boxes bound to the database fields. Code is added to handle the button click events.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
78 views5 pages

Database Design:: Visual Basic

The document describes the design of a home inventory database and application in Microsoft Access. It involves: 1) Creating a single table database with fields to store item details and saving it. 2) Designing a report in the Data Report designer to display the inventory. 3) Building a form in the Visual Basic editor to allow adding, editing, deleting and viewing items with navigation buttons and text boxes bound to the database fields. Code is added to handle the button click events.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

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

You might also like