|
Example Application: FunDS (Fun Department Store) |
|
|
FunDS is an example of a fictitious company that sells
clothes from its store in a mall. The clothes are stacked on shelves and tables
from where customers can view and select them. When interested and after making
a selection, a customer can bring one or more items to a cashier who would
process a purchase order.
|
We will create a database that can assist the company to
manage its business.
Practical
Learning: Introducing Data Entry
|
|
- Start Microsoft Access
- In the File Name text box, replace the name with FunDS (DS stands for department store)
- Click Create
- On the Ribbon, click File -> Options
- On the left list, click Current Database
- Click Overlapping Windows and Compact On Close
- Click OK
- Click OK
- Close Microsoft Access and re-open it with the Fun Department Store
database
Employees and cashiers are staff members who create the
inventory, process customers purchase orders, and perform other management
tasks. We will create a simple table that holds employees information. To keep
the database simple, we will use as little information as possible.
Practical
Learning: Creating the Categories of Items
|
|
- On the Ribbon, click Create and, in the Queries section, click Query
Design
- On the Show Table dialog box, click Close
- Right-click the Query1 window and click SQL View
- Replace the text with the following:
CREATE TABLE Employees
(
EmployeeID Counter(1, 1) Not Null,
EmployeeNumber Text(20),
FirstName Text(25),
LastName Text(25),
FullName Text(50),
Title Text(50),
Notes Note,
Constraint PK_Employees Primary Key(EmployeeID)
);
- To execute the code, on the Ribbon, click the Run button
- On the Ribbon, click Create and, in the Forms section, click Form Design
- Using the Properties window, set the following characteristics:
Record Source: Employees Auto Center: Yes
- Save the form as Employees
- Design it as follows:
- Save the Employees form
- Switch it to Form View
- Create a few records as follows:
Empl # |
First Name |
Last Name |
Full Name |
Title |
60958 |
Simon |
Sielaff |
Sielaff, Simon |
General Manager |
20858 |
Becky |
Crone |
Crone, Becky |
Head Cashier |
40295 |
Catherine |
Rosenstock |
Rosenstock, Catherine |
Cashier |
80284 |
Bernadette |
Wrights |
Wrights, Bernadette |
Cashier |
27046 |
Betty |
Lorre |
Lorre, Betty |
Intern |
60960 |
Lisa |
Chicone |
Chicone, Lisa |
Cashier |
39486 |
Daniel |
Drewise |
Drewise, Daniel |
Shift Manager |
93842 |
Steve |
Goetsch |
Goetsch, Steve |
Cashier |
- Close the form
The clothes that FunDS sells are divided in some categories
for easy inventory. The most common categories include women, men, girls, and
boys. Of course, we will make it possible to add new categories.
Practical
Learning: Creating the Categories of Items
|
|
- Replace the text in the Query1 window with the following:
CREATE TABLE Categories
(
Category Text(40) Not Null,
Constraint PK_Categories Primary Key(Category)
);
- To execute the code, on the Ribbon, click the Run button
- On the Ribbon, click Create and, in the Forms section, click Form Design
- Using the Properties window, set the following properties:
Record
Source: Categories Auto Center: Yes
- Save the form as Categories
- Design it as follows:
- Save the Categories form
- Switch it to Form View
- Create a few records as follows:
Category |
Women |
Men |
Girls |
Boys |
Babies |
- Save and close the Categories form
The Sub-Categories of Items
|
|
To further enhance the inventory, and to better assist
customers, most commercial stores use categories under main categories. These
are referred to as sub-categories. For a department store, sub-categories would
include the types of clothes, such as shirts, dresses, or shoes.
Practical
Learning: Creating the Categories of Items
|
|
- Replace the text in the Query1 window with the following:
CREATE TABLE SubCategories
(
SubCategory Text(40) Not Null,
Constraint PK_SubCategories Primary Key(SubCategory)
);
- To execute the code, on the Ribbon, click the Run button
- On the Ribbon, click Create and, in the Forms section, click Form Design
- Using the Properties window, set the following characteristics:
Record Source: SubCategories Auto Center: Yes
- Save the form as SubCategories
- Design it as follows:
- Save the Sub-Categories form
- Switch it to Form View
- Create a few records as follows:
Sub-Category |
Shirts |
Pants |
Shoes |
Dresses |
Skirts |
Jackets |
Coats |
Suits |
Sweaters |
Belts |
Ties |
Hats |
Handbags |
Watches |
Jewelry |
Accessories |
Beauty & Grooming |
- Close the Sub-Categories form
Manufacturers and people and companies that make clothes
that the Fun Department Store company sells. Normally, a department store keeps
as much information as possible about the manufacturers. Companies also keep
track of their suppliers. To keep our database simple, we will need just the
name of the manufacturer. Many manufacturers use different names to categorize
the items they make. We will create two fields for names for each
manufacturer.
Practical
Learning: Creating the Categories of Items
|
|
- Replace the text in the Query1 window with the following:
CREATE TABLE Manufacturers
(
Manufacturer Text(40) Not Null,
OtherName Text(40),
Notes Note,
Constraint PK_Manufacturers Primary Key(Manufacturer)
);
- To execute the code, on the Ribbon, click the Run button
- On the Ribbon, click Create and, in the Forms section, click Form Design
- Using the Properties window, set the following characteristics:
Record Source: Manufacturers Auto Center: Yes
- Save the form as Manufacturers
- Design it as follows:
- Save the Manufacturers form
- Switch the form to Form View
- Create a few records as follows:
Manufacturer |
Other Name |
Notes |
Ralph Lauren |
Polo Ralph Lauren |
Names include Ralph Lauren, Lauren by Ralph Lauren, Polo Ralph Lauren |
Polo Ralph Lauren |
Ralph Lauren |
Names include Ralph Lauren, Lauren by Ralph Lauren, Polo Ralph Lauren |
Lauren by Ralph Lauren |
Ralph Lauren |
Names include Ralph Lauren, Lauren by Ralph Lauren, Polo Ralph Lauren |
Kenneth Cole |
Kenneth Cole New York |
Names include Kenneth Cole, Kenneth Cole Reaction, Kenneth Cole New York |
Kenneth Cole New York |
Kenneth Cole |
Names include Kenneth Cole, Kenneth Cole Reaction, Kenneth Cole New York |
Kenneth Cole Reaction |
Kenneth Cole |
Names include Kenneth Cole, Kenneth Cole Reaction, Kenneth Cole New York |
Calvin Klein |
CK Calvin Klein |
Names include Calvin Klein, CK Calvin Klein |
CK Calvin Klein |
Calvin Klein |
Names include Calvin Klein, CK Calvin Klein |
Anne Klein |
AK Anne Klein |
Names include Anne Klein, AK Anne Klein |
AK Anne Klein |
Anne Klein |
Names include Anne Klein, AK Anne Klein |
Nautica |
|
|
Tommy Hilfiger |
|
|
Cole Haan |
|
|
Giorgio Armani |
|
|
Timex |
|
|
Johnston & Murphy |
|
|
Citizen |
|
|
Coach |
|
|
Guess |
|
|
Seiko |
|
|
Clarks |
|
|
- Close the Manufacturers form
Probably the most important part of a department store is
the list of items it sells. To keep an inventory, we will use the following
information for each item sold in the store:
- Item Number: This is be a number that uniquely identifies each item of
the department store
- Date Entered: This is the date when the item's information was created
in the inventory
- Manufacturer: This field represents the make of the item
- Category: This field identifies the type of item
- Sub-Category: This is a sub-type of item
- Item Name: This is a short name of the item
- Size: Most clothing items have a size. Some do not
- Unit Price: This is the price of one sample of the item
- Discount Rate: Some items receive a discount. There are various reasons
for this. One reason is that the item may have been in the store for a
while, in which case it would be discounted for fast(er) sale
- Pictures: We will try to provide one or more pictures of the item, when
available
Practical
Learning: Creating the Store Inventory
|
|
- On the Ribbon, click Create
- In the Forms section, click Form Design
- Using the Properties window, change the following characteristics:
Caption: Fun Department Store - New Store Item Auto
Center: Yes Record
Selectors: No Navigation Button: No Dividing Lines: Yes
- Save the form as NewStoreItem
- On the Ribbon, click Design and, in the Controls section, click More.
Make sure the Use Control Wizards option is selected
. In the Controls section of the Ribbon, click the Combo Box
- Click the form (somewhere under the Header bar)
- In the first page of the wizard, make sure the first radio button is
selected and click Next
- In the second page of the wizard, click Table: Manufacturers
- Click Next
- Double-click Manufacturer and OtherName
- Click Next
- Click Next
- Click Next
- Click Finish
- In the Controls section of the Ribbon, click the Combo Box
- Click the form (somewhere under the Header bar)
- In the first page of the wizard, make sure the first radio button is
selected and click Next
- In the second page of the wizard, make sure Table: Categories is
selected and click Next
- Double-click Category
- Click Next
- Click Next
- Click Next
- Click Finish
- In the Controls section of the Ribbon, click the Combo Box
- Click the form (somewhere under the Header bar)
- In the first page of the wizard, make sure the first radio button is
selected and click Next
- In the second page of the wizard, click Table: SubCategories
- Click Next
- Double-click SubCategory
- Click Next
- Click Next
- Click Next
- Click Finish
- Complete the design of the form as follows:
|
Control |
Name |
Caption |
Text Box |
|
ItemNumber |
Item Number: |
Text Box |
|
DateEntered |
Date Entered: |
Combo Box |
|
ManufacturerID |
Manufacturer: |
Button |
|
NewManufacturer |
New... |
Combo Box |
|
CategoryID |
Category: |
Button |
|
NewCategory |
New... |
Combo Box |
|
SubCategoryID |
Sub-Category: |
Button |
|
NewSubCategory |
New... |
Text Box |
|
ItemName |
Item Name: |
Text Box |
|
ItemSize |
Item Size: |
Text Box |
|
UnitPrice |
Unit Price: |
Text Box |
|
DiscountRate |
Discount Rate: |
Text Box |
|
Notes |
Notes: |
Button |
|
cmdSubmit |
Submit |
Button |
|
cmdReset |
Reset |
Button |
|
cmdClose |
Close |
|
- On the form, right-click the Reset button and click Build Event...
- In the Choose Builder dialog box, click Code Builder and click OK
- Implement the event as follows:
Private Function SetDateEntered(ByVal Days As Integer) As Date
SetDateEntered = DateAdd("d", Days, Date)
End Function
Private Sub cmdReset_Click()
ItemNumber = CStr(Int((999999 - 100000 + 1) * Rnd + 100000))
DateEntered = SetDateEntered(-Int(180 * Rnd + 1))
ManufacturerID = ""
CategoryID = ""
SubCategoryID = ""
ItemName = ""
ItemSize = ""
UnitPrice = ""
DiscountRate = "0.00"
End Sub
- In the Object combo box, select Form
- Implement the Load event as follows:
Private Sub Form_Load()
cmdReset_Click
End Sub
- In the Object combo box box, select cmdNewManufacturer
- Implement the event as follows:
Private Sub cmdNewManufacturer_Click()
On Error GoTo cmdNewManufacturer_Error
' Display the Manufacturers form as a dialog box
DoCmd.OpenForm "Manufacturers", , , , acFormAdd, AcWindowMode.acDialog
' After using the Manufacturers form, when the user closes it,
' refresh the Manufacturer combo box
Manufacturer.Requery
cmdNewManufacturer_Exit:
Exit Sub
cmdNewManufacturer_Error:
MsgBox "An error occured when trying to update the list." & vbCrLf & _
"=- Report the error as follows -=" & vbCrLf & _
"Error #: " & Err.Number & vbCrLf & _
"Error Message: " & Err.Description
Resume cmdNewManufacturer_Exit
End Sub
- In the Object combo box, select cmdNewCategory
- Implement the event as follows:
Private Sub cmdNewCategory_Click()
On Error GoTo cmdNewCategory_Error
DoCmd.OpenForm "Categories", , , , acFormAdd, AcWindowMode.acDialog
Category.Requery
cmdNewCategory_Exit:
Exit Sub
cmdNewCategory_Error:
MsgBox "An error occured when trying to update the list." & vbCrLf & _
"=- Please report the error as follows -=" & vbCrLf & _
"Error #: " & Err.Number & vbCrLf & _
"Error Message: " & Err.Description
Resume cmdNewCategory_Exit
End Sub
- In the Object combo box, select cmdNewSubCategory
- Implement the event as follows:
Private Sub cmdNewSubCategory_Click()
On Error GoTo cmdNewSubCategory_Error
DoCmd.OpenForm "SubCategories", , , , acFormAdd, AcWindowMode.acDialog
SubCategory.Requery
cmdNewSubCategory_Exit:
Exit Sub
cmdNewSubCategory_Error:
MsgBox "An error occured when trying to update the list of sub-categories." & vbCrLf & _
"=- Please report the error as follows -=" & vbCrLf & _
"Error #: " & Err.Number & vbCrLf & _
"Error Message: " & Err.Description
Resume cmdNewCategory_Exit
End Sub
- In the Object combo box, select ManufacturerID
- In the Procedure combo box, select NotInList
- Implement the event as follows:
Private Sub ManufacturerID_NotInList(NewData As String, Response As Integer)
On Error GoTo ManufacturerIDNotInList_Error
Dim NewManufacturerID As Long
If IsNull(ManufacturerID) Then
' Set the value of the combo box empty
ManufacturerID = ""
Else
' If the foreign key currently has a value,
' assign that value to the declared value
NewManufacturerID = ManufacturerID
' Set the foreign key to null
ManufacturerID = Null
End If
' The combo box is ready to receive a new value.
' To make it happen, display the Manufacturers form
' as a dialog box so the user would not use
' the Store Items form while the Manufacturers form is opened
' When opening the Manufacturers form, create a new record
' and display the new manufacturer in it
If MsgBox("The '" & NewData & "' manufacturer does not exist in the database. " & _
"Do you want to add it?", _
vbYesNo, "Fun Department Store - FunDS") = vbYes Then
DoCmd.OpenForm "Manufacturers", , , , acFormAdd, AcWindowMode.acDialog, NewData
' After using the Manufacturers dialog box, let the user close it.
' When the user closes the Manufacturers form, refresh the ManufacturerID combo box
Manufacturer.Requery
' If the user had created a new manufacturer,
' assign its ManufacturerID to the variable we had declared
If ManufacturerID <> 0 Then
ManufacturerID = NewManufacturerID
End If
' Assuming that the manufacturer was created, ignore the error
Response = acDataErrAdded
Else
' If the manufacturer was not created, indicate an error
Response = acDataErrContinue
End If
ManufacturerIDNotInList_Exit:
Exit Sub
ManufacturerIDNotInList_Error:
MsgBox "An error occured when trying to update the list." & vbCrLf & _
"=- Report the error as follows -=" & vbCrLf & _
"Error #: " & Err.Number & vbCrLf & _
"Error Message: " & Err.Description
Resume ManufacturerIDNotInList_Exit
End Sub
- In the Object combo box, select CategoryID
- In the Procedure combo box, select NotInList
- Implement the event as follows:
Private Sub CategoryID_NotInList(NewData As String, Response As Integer)
On Error GoTo CategoryIDNotInList_Error
Dim NewCategoryID As Long
If IsNull(CategoryID) Then
CategoryID = ""
Else
NewCategoryID = CategoryID
CategoryID = Null
End If
If MsgBox(NewData & " is not a valid category of this database. " & _
"Do you want to add it?", _
vbYesNo, "Fun Department Store - FunDS") = vbYes Then
DoCmd.OpenForm "Categories", , , , acFormAdd, AcWindowMode.acDialog, NewData
Category.Requery
If CategoryID <> 0 Then
CategoryID = NewCategoryID
End If
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
CategoryIDNotInList_Exit:
Exit Sub
CategoryIDNotInList_Error:
MsgBox "An error occured when trying to update the list." & vbCrLf & _
"=- Report the error as follows -=" & vbCrLf & _
"Error #: " & Err.Number & vbCrLf & _
"Error Message: " & Err.Description
Resume CategoryIDNotInList_Exit
End Sub
- In the Object combo box, select SubCategoryID
- In the Procedure combo box, select NotInList
- Implement the event as follows:
Private Sub SubCategoryID_NotInList(NewData As String, Response As Integer)
On Error GoTo SubCategoryIDNotInList_Error
Dim NewSubCategoryID As Long
If IsNull(SubCategoryID) Then
SubCategoryID = ""
Else
NewSubCategoryID = SubCategoryID
SubCategoryID = Null
End If
If MsgBox(NewData & " is not a valid sub-category of this database. " & _
"Do you want to add it?", _
vbYesNo, "Fun Department Store - FunDS") = vbYes Then
DoCmd.OpenForm "SubCategories", , , , acFormAdd, AcWindowMode.acDialog, NewData
SubCategory.Requery
If SubCategoryID <> 0 Then
SubCategoryID = NewSubCategoryID
End If
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
Exit Sub
SubCategoryIDNotInList_Error:
MsgBox "An error occured when trying to update the sub-categories." & vbCrLf & _
"=- Report the error as follows -=" & vbCrLf & _
"Error #: " & Err.Number & vbCrLf & _
"Error Message: " & Err.Description
Resume Next
End Sub
- Return to Microsoft Access
- In the Navigation Pane, right-click the Manufacturers form and click
Design View
- In the Properties window, click Event and double-click On Load
- Click its ellipsis button to switch to Microsoft Visual Basic
- Implement the event as follows:
Private Sub Form_Load()
' When this form opens, find out if it received an external
' value from another object (such as the StoreItemEditor form).
If Not IsNull(Me.OpenArgs) Then
' If it did, put that value in the Manufacturer text box
Me.Manufacturer = Me.OpenArgs
' Since our database allows up to three different names for
' a manufacturer, the user will optionnally fill the other two text boxes
End If
End Sub
- Return to Microsoft Access
- In the Navigation Pane, right-click the Categories form and click
Design View
- In the Event section of the Properties window, double-click On Load
- Click its ellipsis button and implement the event as follows:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me.Category = Me.OpenArgs
End If
End Sub
- Return to Microsoft Access
- In the Navigation Pane, right-click the SubCategories form and click
Design View
- In the Event section of the Properties window, double-click On Load
- Click its ellipsis button and implement the event as follows:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me.SubCategory = Me.OpenArgs
End If
End Sub
- Return to Microsoft Access
- Close all forms
- When asked to save, save
- Replace the text in the Query1 window with the following:
CREATE TABLE StoreItems
(
StoreItemID COUNTER(100001, 1) NOT NULL,
Constraint PK_StoreItems Primary Key(ItemID)
);
- To execute the code, on the Ribbon, click the Run button
- In the Navigation Pane, right-click StoreItems and click Design View
- Change the list of fields as follows:
Field Name |
Data Type |
Field Size |
Format |
Caption |
StoreItemID |
|
|
|
Store Item ID |
ItemNumber |
Number |
|
|
Item Number |
DateEntered |
Date/Time |
|
Long Date |
Date Entered |
Manufacturer |
Text |
|
40 |
|
Category |
Text |
|
40 |
|
SubCategory |
Text |
|
40 |
Sub-Category |
ItemName |
Text |
80 |
|
Item Name |
ItemSize |
Text |
40 |
|
Item Size |
UnitPrice |
Number |
Double |
Fixed |
|
DiscountRate |
Number |
Double |
Percent |
Discount Rate |
Pictures |
Attachment |
|
|
|
Notes |
Memo |
|
|
|
- Save and close the StoreItems table
- In the Navigation Pane, right-click NewStoreItem and click Copy
- Right-click any part of the Navigation Pane and click Paste
- Type StoreItems as the name of the form
- Click OK
- In the Navigation Pane, right-click the StoreItems table and click
Design View
- Using the Properties window, change the following characteristics:
Record Source: StoreItems
Caption: Fun Department Store - Store Items
Record Selectors: Yes Navigation Buttons: Yes Allow Additions: No (the
new records will be added using the NewStoreItem form; but this form can be
used to update a record; this means that, for example, this form can be used
to add the picture(s) of an item)
- On the form, right-click the Submit button and click Build Event
- In Microsoft Visual Basic, delete the code of the Click event of
cmdSubmit, the Load event of the form, and the Click event of cmdReset
- Return to Microsoft Access
- Delete the Reset button
- Change the characteristics of the Submit button as follows:
Name: cmdNewStoreItem
Caption: New Store Item...
- Complete the design of the form as follows (appropriately set the
Control Source of each control, it is the same as the name of the control):
- Save the form
- Right-click the New Store Item button and click Build Event...
- In the Choose Builder dialog box, double-click Code Builder
- CliClick the ellipsis button and implement the event as follows:
Private Sub cmdNewStoreItem_Click()
DoCmd.OpenForm "NewStoreItem"
End Sub
- Save and close the StoreItems form
- In the Navigation Pane, right-click the Submit button and click Build
Event...
- Double-click Code Builder
- Implement the event as follows:
Private Sub cmdSubmit_Click()
Dim curFunDS As Database
Dim rstStoreItems As Recordset
Set curFunDS = CurrentDb
Set rstStoreItems = curFunDS.OpenRecordset("StoreItems")
rstStoreItems.AddNew
rstStoreItems("ItemNumber").Value = ItemNumber
rstStoreItems("DateEntered").Value = CDate(DateEntered)
rstStoreItems("ManufacturerID").Value = ManufacturerID
rstStoreItems("CategoryID").Value = CategoryID
rstStoreItems("SubCategoryID").Value = SubCategoryID
rstStoreItems("ItemName").Value = ItemName
rstStoreItems("ItemSize").Value = ItemSize
rstStoreItems("UnitPrice").Value = CDbl(UnitPrice)
rstStoreItems("DiscountRate").Value = CDbl(DiscountRate)
rstStoreItems("Notes").Value = Notes
rstStoreItems.Update
cmdReset_Click
Set rstStoreItems = Nothing
Set curFunDS = Nothing
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
- In the Navigation Pane, double-click NewStoreItem
- Create the Store Items
- Close the form
We will consider a shopping session one more items that a
customer purchases. Normally, a customers selects items in the store and brings
them to the cashier who will vallidate the purchase. For our database, we will
create a unique receipt number. For our inventory, we will need to keep track of
who (the employee) processed the purchase, the date and time the purchase
occured, and the total the customer paid.
|
|