Professional Documents
Culture Documents
Book
Book
Book
Room M1 Group 5 1
Block (. (. Lucky ) )
Room M1 Group 5
,
2
, , , ,
Room M1 Group 5
: Logical Design II. Entity set II.1 Strong Entity set Strong Entity set Entity set Entity set Entity set Entity set
Room M1 Group 5
Associative: o
o
II.3 Entity set (Entity- Relationship Modeling ) II.3.1 Entity sets: Database ERM ERM ERD (Entity Relationship Diagram)ERD
(0:1)
(1:1)
(1:1)
(0:M)
(0:M)
E
Room M1 Group 5
(1:M)
(1:M)
E
5
a1 a2 Has (1:1)
Rent
(1:M)
Customer
a1
a2 Has (1:1)
Rent
(0:M)
Staff
Rent
Store
-
a1 (1:1) a2 (1:M) RentDetail b1 (0:M) Has b2 (1:1)
Rent
Has
Store
Room M1 Group 5
+ + + + a1: RentDetail Rent a2: Rent RentDetail b1: Store RentDetail b2: RentDetail Store
a1 a2 Has (1:1)
Import
(0:M)
Staff
Import
Supplier
Import
Product
Import
Has
Product
Room M1 Group 5 7
+ + + +
a1: ImportDetail Import a2: Import ImportDetail b1: Product ImportDetail b2: ImportDetailProduct
a1 (0:M) Has
a2 (1:1)
Payment
Staff
Payment
(1:M)
Customer
Expensed
(0:M)
Staff
Room M1 Group 5
a1 (1:M) Has
a2 (1:1)
Store
StorType
II.4 Entity ( Entity- Relation Diagram ERD-) Entity set ERD ERD
Entity set Entity set Entity set Entity set Entity set Entity set
Room M1 Group 5
Room M1 Group 5
10
Table Strong Entity set Table Primary key Field Entity set Table Table Associative Entity set Foreign Key Primary key Table Primary key Foreign key Foreign key Field Primary key Entity set code ID, No,
Table field StrongEntity set 1) tbStaff(StaffID, StaffName, Gender, BirthDate, Address, Phone, Position, Salary, HireDate) 2) tbCustomer(CusID, CusName, Address, Phone) 3) tbSupplier(SupID, Supplier, SupPhone, SupAddress) 4) tbStoreType(TpyeID,StoreType.Price) WeakEntity set 5) tbProduct(ProductID, ProductName, Quantity, Unitprice, Category) 6) tbStore(StoreID, TypeID,Floor,Status) 7) tbPayment(PaymentID, PaymentDate, CusID, StaffID, PaymentAmount, ExchangeRate) 8) tbImport(ImportID, ImportDate, SupID, StaffID, TotalAmount, ExchangRate) 9) tbImportDetail(ImportID,ProductID, ImportQty, UnitePrice, Discount, Amount) 10) tbRent(RentID, RentDate, CusID, StaffID, ExpireDate,Books, TotalAmount,RemaindAmount,Exchange)
Room M1 Group 5 11
11) tbRentDetail(RentID,StoreID, RentQty, Unitprice, Discount, Amount) 12) tbExpent(ExspentID, ExspentDate,StaffID, Description , Amount)
Room M1 Group 5
12
: Physical Design
III. DatabaseManagerment System Data Dictionary Table Fields Table Field (Properties) Field Field Primary Key Field Table
Room M1 Group 5
13
ERD 1. tbStaff tbStaff Fields Field Field Fields properties Fields Name StaffID StaffName Gender BirthDate Address Phone Position Salary HireDate Data type Number Text Text DateTime Text Text Text Currency DateTime Fields size Smallint 30 1 100 15 30 #,##0.00 $ > Format 0000 Allow zero length No No No Yes No dd-mmm-yyyy dd-mmm-yyyy
2. tbCustomer Customer
Format 0000
3. tbSupplier
tbSupplier Fields Field Field Fields properties Data type Number Text Text Text Allow zero length No No No
Format 0000
4. tbStoreType
Room M1 Group 5
15
5. tbStore
6. tbProduct
tbProduct Fields Field Field Fields properties Data type Number Text Number Currency Text Allow zero length No #,##0.00 $ No
Format 0000
Room M1 Group 5
16
7. tbPayment
dd-mmm-yyyy
PaymentAmount Currency
8. tbImport
tbImport Fields Field Field Fields properties Data type Number DateTime Number Number Currency Currency Allow zero length
dd-mmm-yyyy
Room M1 Group 5
17
9. tbImportDetail
tbImportDetail Fields Field Field Fields properties Data type Number Number Number Currency Currency Currency Allow zero length #,##0.00 $ #,##0.00$ #,##0.00$
10. tbRent
tbRent Fields Field Field Fields properties Data type Number DateTime Number Number DateTime Currency Currency Currency Currency Currency Allow zero length
Fields Name RentID RentDate CusID StaffID ExpireDate Books TotalAmount Remain Amount ExchangRate
dd-mmm-yyyy
dd-mmm-yyyy
Room M1 Group 5
18
11. tbRentDetail
tbRentDetail Fields Field Field Fields properties Data type Number Number Currency Currency Currency Allow zero length #,##0.00 $ #,##0.00$ #,##0.00$
Format 0000
12. tbExspent
tbExspent Fields Field Field Fields properties Data type Number DateTime Number Currency Text Allow zero length No
dd-mmm-yyyy
Room M1 Group 5
19
III. 2. Form Database system ERD Form Database System Form Table Strong Entity set Form Table Strong Entity set Form Form Table Strong Entity set Entity set Search Form Form Table Weak Entity Set Weak Entity set Form Table Weak Entity set (, Search ) Form Form , Assignment
Form Search
Room M1 Group 5
20
ERD Form 11
frmStaff
Search StaffName :
Staffs List StaffID : StaffName : Gender : BirthDate : Address : Phone : Position : Salary : HireDate : StopWork : Close New Save
Room M1 Group 5
21
Update Table
frmStoreType
StoeType :
4).frmSupplier
Table tbSupplier
Search
Update
frmSupplier
Search SupName:
Room M1 Group 5
22
Update
frmCustomer
Search Customer :
Update Close
Database System -
In
tbCustomer : tbRent :
Room M1 Group 5
23
Form
frmRent
New Customer
Details Information:
Store Name : Floor StoreType Status UnitPrice : Discount :
StoreID
StoreName
StoreType
Floor
Quantities
UnitPrice
Discount
Exchange Rate :
Room M1 Group 5
24
(Re-
RemainAmount
Form
tbPayment :
Room M1 Group 5
25
In
tbProduct :
Form
Form Expense
tbExpense :
Room M1 Group 5
26
tbProduct
Update Unit
CategoryForm Price
Field Form
tbCategory Sale
FrmProduct
Search Product : Search Category: Products List ProductID :TypeID : ProductName: Quantity: Unitprice:StoreType : Update Close
+ Detail : -
Category Category
tbProduct : ?
Room M1 Group 5
27
Form
frmImport
Details Information:
Category : Product ID : ProductName : ImportQty : UnitPrice :
ProductID
ProductName
CategoryID
Category
ImportQty
UnitPrice
Amount
Add Remove
Room M1 Group 5
28
4. Table Table Deseing SQL Table SQL 4.1.1 Table SQL a. Table Strong tbStaff Create Table tbStaff(StaffIDSmallint Primary Key, StaffName Text(30), Gender Text(1), BirthDateDateTime, Address Text(100), Phone Text(15), Position Text(30), Salary Currency, HireDateDateTime, StopworkYesNo); tbCustomer Create Table tbCustomer(CusIDSmallint Primary Key, CusName Text(30), Address Text(100), Phone Text(15)); tbSupplier Create Table tbSupplier(SupIDsmallint Primary Key, SupName Text(50), SupPhone Text(13), SupAddress Text(50)); tbStoreType Create Table tbStoreType(TypeID Byte Primary Key, StoreType Text(20), Price Currency); b. Table Weak tbImport Create Table tbImport(ImportIDSmallint Primary Key, ImportDateDateTime, SupIDSmallint, StaffIDSmallint, TotalAmount Currency, ExchangeRate byte, Table Table 2
Room M1 Group 5
29
Constraint FkSupID Foreign Key (SupID) References tbSupplier(SupID), Constraint Fk1StaffID Foreign Key (StaffID) References tbStaff(StaffID)) tbRent Create Table tbRent(RentIDSmallint Primary Key , RetDateDateTime, CusIDSmallint, StaffIDSmallint, ExpireDateDateTime, Books YESNO, TotalAmount Currency, RemainAmount Currency, ExchangeRate Currency, Constraint Fk1CusID Foreign Key (CusID) References tbCustomer(CusID), Constraint Fk2StaffID Foreign Key (StaffID) References tbStaff(StaffID)) tbPayment Create Table tbPayment(PaymentIDSmallint Primary Key, PaymentDateDateTime, CusIDSmallint, StaffIDSmallint, PaymentAmount Currency, ExchangeRate byte, Constraint FkCusID Foreign Key (CusID) References tbCustomer(CusID), Constraint FkStaffID Foreign Key (StaffID) References tbStaff(StaffID)) tbProduct Create Table tbProduct (ProductIDSmallint Primary Key, ProductName Text(50), Quantity Smallint, UnitPrice Currency,Category Text(30)); tbStore Create Table tbStore(StoreNo Integer Primary Key, StoreName Text(5), TypeID Byte, Floor byte, Status Text(20), constraint FkTypeID Foreign key (TypeID) References tbStoreType(TypeID)); tbExpense Create Table tbExspense( ExspenseNoSmallint Primary Key, ExpenseDateDateTime, StaffIDSmallint, Description Text(30), Amount Currency, Constraint FK4StaffID Foreign Key(StaffID) References tbStaff(StaffID));
Room M1 Group 5
30
a. Associative table Create Table tbRentDetail(RentIDSmallint, StoreIDsmallint , RentQtysmallint, UnitPrice Currency, Discount Byte, Amount Currency, Constraint FKRentID Foreign Key(RentID) References tbRent(RentID), Constraint FkStoreID Foreign Key(StoreID) References tbStore(StoreID), Constraint PkRentIDStoreID Primary Key(RentID,StoreID)); Create Table tbImportDetail(ImportIDSmallint, ProductIDSmallint, ImportQtysmallint, UnitPrice Currency, Discount byte, Amount Currency, Constraint FkImportID Foreign Key (ImportID) References tbImport(ImportID), Constraint FkProductID Foreign Key (ProductID) References tbProduct(ProductID),Constraint PkImIDProID Primary Key (ImportID, ProductID)); 4.1.2 Module Object 1. Function Auto ID Function Auto(tb As String, fd As String) As Long Dim db As DAO.Database, rs As DAO.Recordset Dim stSQL As String, x As Long Dim st As String, y As Integer y = Year(Date) stSQL = "Select " &fd& " From " _ &tb& " Where Left(" &fd& ",4)=" _ & y &" Order by " &fd Set db = CurrentDb() Set rs = db.OpenRecordset(stSQL) With rs If .RecordCount = 0 Then x=1 st = y & Format(x, "000000")
Room M1 Group 5 31
x = CLng(st) Else . MoveLast x = .Fields(0) + 1 End If .Close End With Set db = Nothing Auto = x End Function 2. Function AutoCompleteNum ID ID Function AutoNumber(tb$, fd$) As Long Dim db As DAO.Database, rs As DAO.Recordset Dim stSQL As String, x As Long stSQL = "Select " &fd& " From " &tb _ &" Order by " &fd Set db = CurrentDb() Set rs = db.OpenRecordset(stSQL) With rs If .RecordCount = 0 Then x=1 Else . MoveLast x = .Fields(0) + 1 End If .Close End With
Room M1 Group 5 32
Set db = Nothing AutoNumber = x End Function 3. Function CheckNull Text Box Combo Box Box Text Box Combo Box Null Text Box Combo Function checkNull(ParamArrayCtr()) As Boolean Dim i As Byte, b As Boolean, ctrName As String For i = 0 To UBound(Ctr()) If IsNull(Ctr(i)) Then ctrName = Right(Ctr(i).Name, Len(Ctr(i).Name) - 3) b = True MsgBox "Please, Fill data in "&ctrName, vbInformation, _ " Information" Ctr(i).SetFocus Exit For End If Next checkNull = b End Function 4. Sub Procedure clear Text Box Combo Box Sub clearcontrol(frm As Form) Dim c As Control For Each c Infrm.Controls If TypeOf c Is TextBoxOrTypeOf c Is ComboBox Then If c.Tag = "" Then c.value = Null End If
Room M1 Group 5 33
Next End Sub 5. Sup Procedure clear Text Box Text Box Sub ClearCtr(ParamArray Ctr()) Dim i As Byte For i = 0 To UBound(Ctr()) Ctr(i).value = Null Next End Sub 6. Sub procedure AddNew Record Public Sub AddNewRecord(tb As String, ParamArray Data()) Dim db As DAO.Database, rs As DAO.Recordset Dim stSQL As String, i As Integer stSQL = "select top 1 * from " & tb Set db = CurrentDb() Set rs = db.OpenRecordset(stSQL) With rs . AddNew For i = 0 To UBound(Data()) . Fields(i) = Data(i) Next . Update . Close End With Set db = Nothing End Sub
Room M1 Group 5
34
7. Sub procedure Edit Record Public Sub EditRecord(tb$, fd$, ParamArray Data() As Variant) Dim db As DAO.Database, rs As DAO.Recordset Dim stSQL As String, i As Integer Set db = CurrentDb() stSQL = "select * from " & tb & " where " & fd & "=" & Data(0) Set rs = db.OpenRecordset(stSQL) With rs . Edit For i = 1 To UBound(Data()) . Fields(i) = Data(i) Next . Update . Close End With Set db = Nothing End Sub
8. Function Close Button Public Sub CloseForm(frm As Form) Dim Y As Variant Y = MsgBox("Are you sure, you want to Close Form?", vbInformation + vbYesNo, "Close") If Y = vbNo Then Exit Sub DoCmd.Close acForm, frm.Name, acSaveYes
Room M1 Group 5 35
End Sub 9. Function Encrypt data Function EncryptData(stData As String) As String Dim i As Integer, n As Byte Dim st As String, stResult As String n = Len(stData) st = StrReverse(stData) For i = 1 To n stResult = stResult + Chr(Asc(Mid(st, i, 1)) + 10) _ + Chr(15) Next EncryptData = stResult End Function 10. Funciton Descrypt data Function DecryptData(stData As String) As String Dim i As Integer, n As Byte Dim st As String, stResult As String n = Len(stData) For i = 1 To n If Mid(stData, i, 1) <> Chr(15) Then st = st + Chr(Asc(Mid(stData, i, 1)) - 10) End If Next stResult = StrReverse(st) DecryptData = stResult End Function
Room M1 Group 5
36
11. Function Check Supplier Function checkSupName(c As String) As Boolean Dim b As Boolean Set rs = CurrentDb.OpenRecordset("tbsupplier") With rs If .RecordCount = 0 Then b = False Else .MoveFirst Do While Not .EOF If c = .Fields(1) Then b = True Exit Do End If .MoveNext Loop End If .Close End With checkSupName = b End Function 12. Sup Procedure Remove Item list Sub RemoveListItem(lst As ListBox) Dim i As Integer, indexArr() As Integer Dim n As Integer With lst For i = .ListCount - 1 To 1 Step -1 If .Selected(i) = True Then
Room M1 Group 5 37
n=n+1 ReDim Preserve indexArr(n) indexArr(n - 1) = i End If Next For i = 0 To n - 1 . RemoveItem (indexArr(i)) Next End With End Sub ----------------------------------------------------------------------
Room M1 Group 5
38
Name: txtUserName Tab stop: Yes staffName( Text Box) Name: txtPassword Tab stop: Yes Lock: No Ok ( Button) Name: cmdOK Caption: &OK Cancel ( Button) Name: cmdCancel Caption: &Cancel
a. Property Form ( Event) .On Load: [Event Procedure] Private Sub Form_Load() Call ClearControl(Me) End Sub
Room M1 Group 5
39
b. Property New Button .On Click: [Event Procedure] Private Sub cmdOk_Click() Dim b As Boolean Static x As Byte Set db = CurrentDb() Set rs = db.OpenRecordset("tbUser") With rs If .RecordCount = 0 Then x=x+1 b = False Else Do While Not .EOF If txtUserName = .Fields(1) And txtPassword = .Fields(2) Then b = True sid = .Fields(3) pos = DLookup("Position", "tbStaff", "StaffID=" & sid) If pos = "Manager" Then DoCmd.OpenForm "frmMain" DoCmd.Close acForm, Me.Name, acSaveYes ElseIf pos = "Accountant" Then
Room M1 Group 5 40
DoCmd.OpenForm "frmMain" Form_frmMain.cmdStaff.Enabled = False DoCmd.Close acForm, Me.Name, acSaveYes Else DoCmd.OpenForm ("frmMain") Form_frmMain.cmdStaff.Enabled = False Form_frmMain.cmdCashIncome.Enabled = False Form_frmMain.cmdCashIncome.Enabled = False DoCmd.Close acForm, Me.Name, acSaveYes End If Exit Do End If .MoveNext Loop .Close End If End With If b = False Then x=x+1 Select Case x
Room M1 Group 5 41
Case 1 MsgBox "Try again ! ", vbCritical, "Log in Form" txtPassword.SetFocus Case 2 MsgBox "This is the last time", vbCritical, "Log in Form" txtPassword.SetFocus Case Else MsgBox "Shutdown.", vbCritical, "Log in Form" Call Shell("C:\windows\system32\shutdown.exe /s t 00 ", 1) End Select Call ClearControl(Me) txtUserName.SetFocus End If End Sub c. Property Cencel .On Click: [Event Procedure] Private Sub cmdCancel_Click() DoCmd.Quit End Sub
Room M1 Group 5
42
2. Form Main
Room M1 Group 5
Customer ( Button) Name: cmdCustomer Caption: &Customer Staff ( Button) Name: cmdStaff Caption: &Staff Supplier ( Button) Name: cmdSupplier Caption: &Supplier Rent ( Button) Name: cmdRent Caption: &Rent New ( Button) Name: cmdProduct Caption: &Product
43
New ( Button)
Name: cmdNew Caption: &New Product ( Button) Name: cmdProduct Caption: &Product User ( Button) Name: cmdUser Caption: &User BackUp ( Button) Name: cmdBackUp Caption: &BackUp Store ( Button) Name: cmdStore Caption: &Store Store ( Button) Name: cmdStoreType Caption: &StoreType Expense ( Button) Name: cmdExpense Caption: &Expense Payment ( Button) Name: cmdPayment Caption: &Payment CashIncome ( Button) Name: cmdCashIncome Caption: &CashIncome
Room M1 Group 5
44
Import ( Button)
Name: cmdImport Caption: &Import About ( Button) Name: cmdAbout Caption: &About Property Form ( Event) .On Click: [Event Procedure] Private Sub Form_Load() DoCmd.Maximize 'Picture = CurrentProject.Path & "\Background.jpg" DoCmd.OpenForm "frmLogIn", , , , , acWindowNormal 'cmdStaff.Enabled = False End Sub Property Customer Button .On Click: [Event Procedure] Private Sub cmdCustomer_Click() DoCmd.OpenForm "frmCustomer", , , , , acDialog End Sub Properties Customer Button . After Update: [Event Procedure] Private Sub cmdCustomer_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblInformation.Caption = "Click here to search information of customer, and you can update or edit Name,Telephone,and Address of customer by click on Update Button.In addition, you can exit by click on Close Button."
Room M1 Group 5 45
lblInformation.FontItalic = True End Sub -------------------------------------------------------------- Property Staff Button .On Click: [Event Procedure] Private Sub cmdStaff_Click() DoCmd.OpenForm "frmStaff", , , , , acDialog End Sub Properties Staff Button . After Update: [Event Procedure] Private Sub cmdStaff_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblInformation.Caption = "Click here to search information of Staff, and you can add, update and delete or edit Name,Telephone,and Address of Staff by click on Update Button.In addition, you can exit by click on Close Button." lblInformation.FontItalic = True End Sub -------------------------------------------------------------- Property Supplier Button .On Click: [Event Procedure] Private Sub cmdSupplier_Click() DoCmd.OpenForm "frmSupplier", , , , , acDialog End Sub
Room M1 Group 5
46
Properties Supplier Button . After Update: [Event Procedure] Private Sub cmdSupplier_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblInformation.Caption = "Click here to search information of supplier, and you can update or edit Name,Telephone,and Address of supplier by click on Update Button.In addition, you can exit by click on Close Button." lblInformation.FontItalic = True End Sub a. Property Rent Button .On Click: [Event Procedure] Private Sub cmdRent_Click() DoCmd.OpenForm "frmRent", , , , , acDialog End Sub Properties Rent Button . After Update: [Event Procedure] Private Sub cmdRent_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblInformation.Caption = "Click here to search information of customer, and you can update or edit Name,Telephone,and Address of customer by click on Update Button.In addition, you can exit by click on Close Button." lblInformation.FontItalic = True End Sub -----------------------------------------------------------------------b. Property Product Button .On Click: [Event Procedure]
Room M1 Group 5 47
Private Sub cmdProduct_Click() DoCmd.OpenForm "frmProduct", , , , , acDialog End Sub Properties Product Button . After Update: [Event Procedure] Private Sub cmdProduct_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblInformation.Caption = "Click here to search information of customer, and you can update or edit Name,Telephone,and Address of customer by click on Update Button.In addition, you can exit by click on Close Button." lblInformation.FontItalic = True End Sub --------------------------------------------------------------c. Property User Button .On Click: [Event Procedure] --------------------------------------------------------------d. Property Backup Button .On Click: [Event Procedure] --------------------------------------------------------------e. Property Store Button .On Click: [Event Procedure] Private Sub cmdStore_Click() DoCmd.OpenForm "frmStore", , , , , acDialog End Sub
Room M1 Group 5 48
Properties Store Button . After Update: [Event Procedure] Private Sub cmdStore_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblInformation.Caption = "Click here to search information of Store, you can add and update or edit Name,Telephone,and Address of customer by click on Update Button.In addition, you can exit by click on CloseButton." lblInformation.FontItalic = True End Sub ---------------------------------------------------------------
f. Property StoreType Button .On Click: [Event Procedure] Private Sub cmdStoreType_Click() DoCmd.OpenForm "frmStoreType", , , , , acDialog End Sub
Properties StoreType Button . After Update: [Event Procedure] Private Sub cmdStoreType_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblInformation.Caption = "Click here to search information of customer, and you can update or edit Name,Telephone,and Address of
Room M1 Group 5 49
customer by click on Update Button.In addition, you can exit by click on Close Button." lblInformation.FontItalic = True End Sub -------------------------------------------------------------g. Property Exspense Button .On Click: [Event Procedure] Private Sub cmdExspense_Click() DoCmd.OpenForm "frmExpense", , , , , acDialog End Sub Properties Exspense Button . After Update: [Event Procedure] Private Sub cmdExspense_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblInformation.Caption = "Click here to search information of customer, and you can update or edit Name,Telephone,and Address of customer by click on Update Button.In addition, you can exit by click on Close Button." lblInformation.FontItalic = True End Sub --------------------------------------------------------------h. Property Payment Button .On Click: [Event Procedure] --------------------------------------------------------------i. Property Cash Income Button .On Click: [Event Procedure]
Room M1 Group 5 50
Private Sub cmdCashIncome_Click() DoCmd.OpenForm "frmCashIncome", , , , , acDialog End Sub Properties Cash Income Button . After Update: [Event Procedure] Private Sub cmdCashIncome_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblInformation.Caption = "Click here to search information of customer, and you can update or edit Name,Telephone,and Address of customer by click on Update Button.In addition, you can exit by click on Close Button." lblInformation.FontItalic = True End Sub --------------------------------------------------------------j. Property Import Button .On Click: [Event Procedure] -------------------------------------------------------------- About ( Label Box)
Name: tlblAbout Caption : About m. Property IblAbout .On Click: [Event Procedure] Private Sub LblAbout_Click() DoCmd.OpenForm "frmAuthor", , , , , acDialog End Sub
Room M1 Group 5 51
Properties lblAbout . After Update: [Event Procedure] Private Sub LblAbout_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) lblAbout.FontItalic = True lblAbout.FontUnderline = True lblAbout.FontSize = 20 End Sub --------------------------------------------------------------k. Property Exit Button .On Click: [Event Procedure] Private Sub cmdExit_Click() ' DoCmd.Quit acQuitSaveAll Call CloseForm(Me) 3. FormUser
Room M1 Group 5
Room M1 Group 5
53
Room M1 Group 5
54
Room M1 Group 5
55
Room M1 Group 5
56
4. Form Staff staffID ( Text Box) Name: txtStaffID Format: 0000 Tab stop: No Locked: Yes staffName( Text Box) Name: txtStaffName Tab stop: Yes Lock: No CboGender ( Combo Box) Name: cboGender Row source Type: Value List Row source: "F";Female;"M";Male Column count: 2 Column Head: No Column Width: 0;1 Bound Column: 1 BirthDate( Text Box) Name: txtBirthDate Format: dd/mmm/yyy Address( Text Box) Phone ( Text Box) Name: txtAddress Name: txtPhone Input Mask: (000)-000-0009 Position ( combo Box)
57
Room M1 Group 5
Name: cboPosition Row source Type: Table/Query Bound Column: 1 Column Count: 1 Salary( Text Box) Name: txtSalary Format: Currency HireDate( Text Box) Name: txtHireDate Format: dd/mmm/yyy CboStopWork ( Combo Box) Name: cboStopWork Row source Type: Value List Row source: "-1";Yes;"0";No Column count: 2 Column Head: No Column Width: 0;1 Bound Column: 1 InputSearch( Text Box) Name: txtInputsearch Tag: * List Staff ( List Box)
Name: lstStaff Row source Type: Table/Query Bound Column: 1 Column Count: 2 Column Width: 0;1
58
Room M1 Group 5
Multi Select: None New ( Button) Name: cmdNew Caption: &New Save ( Button) Name: cmdSave Caption: &Save Close ( Button) Name: cmdSave Caption: &Save
a. Property Form ( Event) .On Load: [Event Procedure] Private Sub Form_Load() DoCmd.Maximize Dim stSQL1 As String stSQL1 = "Select staffID, StaffName from tbStaff order by StaffName " LstStaff.RowSource = stSQL1 txtStaffID.Locked = True cmdNew.SetFocus cmdSave.Enabled = False cmdDelete.Enabled = False Call ClearControl(Me) End Sub ===================================== b. Property New Button .On Click: [Event Procedure] Private Sub CmdNew_Click() Call ClearControl(Me)
Room M1 Group 5 59
txtStaffID = AutoCompleteNum("tbStaff", "StaffID") txtStaffName.SetFocus cmdSave.Enabled = True ststaff = "New" End Sub ----------------------------------------------------------------------c. Property List Staff On Click: [Event Procedure] Private Sub LstStaff_Click() stSQL = "Select * From tbStaff Where StaffID=" & LstStaff.Column(0) Set db = CurrentDb() Set rs = db.OpenRecordset(stSQL) txtStaffID.value = rs(0) txtStaffName.value = rs(1) cboGender.value = rs(2) txtBirthDate.value = rs(3) txtAddress.value = rs(4) txtStaffPhone.value = rs(5) cboPosition.value = rs(6) txtSalary.value = rs(7) txtHireDate.value = rs(8) cboStopWork.value = CInt(rs(9)) ststaff = "Old" cmdSave.Enabled = True cmdDelete.Enabled = True End Sub ----------------------------------------------------------------------- Sub Procedure Display
Room M1 Group 5 60
Private Sub display() Set db = CurrentDb() Set rs = db.OpenRecordset("tbStaff") With rs txtStaffID = .Fields(0) txtStaffName = .Fields(1) cboGender = .Fields(2) txtBirthDate = .Fields(3) txtAddress = .Fields(4) txtStaffPhone = .Fields(5) cboPosition = .Fields(6) txtSalary = .Fields(7) txtHireDate = .Fields(8) cboStopWork = CInt(.Fields(9)) ststaff = " Old" End With End Sub -----------------------------------------------------------------------d. Property Save Button .On Click: [Event Procedure] Private Sub cmdSave_Click() Dim chk As Boolean chk = CheckNull(txtStaffName, cboGender, txtBirthDate, txtAddress, txtStaffPhone, cboPosition, txtSalary, txtHireDate, cboStopWork) If chk = True Then Exit Sub If ststaff = "New" Then txtStaffID = AutoCompleteNum("tbStaff", "StaffID")
Room M1 Group 5
61
Call AddNewRecord("tbStaff", txtStaffID, txtStaffName, cboGender, txtBirthDate, txtAddress, txtStaffPhone, cboPosition, txtSalary, txtHireDate, cboStopWork) MsgBox "Inserted Completely", vbInformation, "Information" LstStaff.Requery ElseIf ststaff = "Old" Then Call EditRecord("tbStaff", "StaffID", txtStaffID, txtStaffName, cboGender, txtBirthDate, txtAddress, txtStaffPhone, cboPosition, txtSalary, txtHireDate, cboStopWork) MsgBox "Updated Completely", vbInformation, "Information" End If Call ClearControl(Me) Call Form_Load End Sub e. Property Delete Button .On Click: [Event Procedure] Private Sub CmdDelete_Click() Dim db As DAO.Database Set db = CurrentDb() db.Execute "Delete from tbStaff where StaffID=" & txtStaffID.value MsgBox "Delete completely", vbInformation, " Information" LstStaff.Requery Call ClearControl(Me) End Sub ----------------------------------------------------------------------f. Property Text box InputSearch .On Key UP: [Event Procedure] Private Sub txtInputSearch_KeyUp(KeyCode As Integer, Shift As Integer)
Room M1 Group 5 62
stSQL = "Select StaffID, StaffName From tbstaff " & " Where StaffName Like '" & txtInputSearch.Text & "*' Order By StaffName" LstStaff.RowSource = stSQL If LstStaff.ListCount = 0 Then Call ClearControl(Me) txtInputSearch.SetFocus txtInputSearch.SelStart = Len(txtInputSearch.Text) Exit Sub End If LstStaff.Selected(0) = True Call LstStaff_Click End Sub ----------------------------------------------------------------------- Properties InputSearch . After Update: [Event Procedure] Private Sub txtInputSearch_AfterUpdate() txtInputSearch.value = Null txtInputSearch.SetFocus End Sub . On Key Press: [Event Procedure] Private Sub txtInputSearch_KeyPress(KeyAscii As Integer) If KeyAscii >= vbKeyA And KeyAscii <= vbKeyZ Or _ KeyAscii >= Asc("a") And KeyAscii <= Asc("z") Or _
KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Or KeyAscii = Asc(" ") Then
MsgBox "You can not input number", vbCritical, "Warmming" Beep End If End Sub -----------------------------------------------------------------------g. Property Close Button Private Sub cmdClose_Click() Call CloseForm(Me) End Sub 5. Form Customer txtCusID ( Text Box) Name: txtCusID Format: 0000 txtCusName( Text Box) txtPhone ( Text Box)
txtAddress( Text Box) txtSearch( Text Box) List Customer ( List Box)
Name: txtAddress Name: txtSearch Name: lstCustomer Row source Type: Table/Query Bound Column: 1 Column Count: 2
64
Column Width: 0;1 Multi Select: None Private Sub Form_Load() DoCmd.Maximize Dim st As String st = " select cusid,cusname from tbcustomer order by cusid" lstCustomer.RowSource = st txtSearch.SetFocus cmdUpdate.Enabled = False End Sub --------------------------------------------------------------
b. Property Update Button . On Click Private Sub cmdUpdate_Click() Dim db As DAO.Database Dim id As Integer Dim chk As Boolean, st As String Dim n As String, p As String, a As String chk = CheckNull(txtCusName, txtPhone, txtAddress) If chk = True Then Exit Sub id = txtCusID.value n = txtCusName.value p = txtPhone.value a = txtAddress.value n = StrConv(n, vbProperCase)
Room M1 Group 5 65
n = "'" & Replace(n, "'", "''") & "'" p = "'" & p & "'" a = "'" & a & "'" Set db = CurrentDb() db.Execute "update tbCustomer set cusname=" & n & ",phone=" & p & ", address=" & a & " where cusid=" & id MsgBox "Update has been saved already!", vbInformation, "Information" lstCustomer.Requery Call ClearControl(Me) End Sub
6. FormCaseIncome InputForm ( Text Box) Name: txtForm Format: dd/mmm/yyyy Tab stop: Yes InputForm ( Text Box)
Locked: No
Name: txtTo Format: dd/mmm/yyyy Tab stop: Yes Locked: No List ( List Box) Name: LstRent Format:
66
Room M1 Group 5
-column count : 5 -Column widths: 1.5";2";1.3";1.3";1" -Column Head :yes Tab stop: Yes Locked: No Search Button: Name: cmdsearch Caption :&Search Close Button: Name: cmdClose Caption :C&lose Total Amount ( Text Box) Name: txtAmount Format: Currency Tab stop: Yes Locked: No Private Sub Form_Load() Call ClearControl(Me) End Sub b. Property Search Button .On Click:[Event Procedure]: Private Sub cmdSearch_Click() Dim sd, st Dim i As Integer, total As Currency sd = txtFrom st = txtTo
Room M1 Group 5 67
If IsNull(sd) Then MsgBox "Please input Search Date!",vbInformation, "Information" txtFrom.value = Null txtFrom.SetFocus ElseIfIsNull(st) Or sd>st Then MsgBox " Wrong Date!"&vbCrLf&" Please input To date!", vbInformation, " Information" txtTo.value = Null txtTo.SetFocus Else sd = "#" &sd& "#" st = " #" &st& "#" LstRent.RowSource = "SELECT r.RentID, CusName, RentDate, ExpireDate,TotalAmount as Amount From tbCustomer As c inner join (tbRent As r inner join tbRentDetail as d On r.RentID=d.RentID) On c.CusID=r.CusID where RentDate between " &sd& " And " &st& " order By RentDate" For i = 1 ToLstRent.ListCount - 1 total = total + LstRent.Column(4, i) Next txtAmount.value = total End If End Sub c. Property Close Button .On Click:[Event Procedure]: Call CloseForm(Me) End Sub
Room M1 Group 5 68
7. FormExpense ExpenceNo ( Text Box) Name: txtExpenceNo Tab stop: Yes Locked: Yes ExpenceDate ( Text Box) Name: txtExpenceDate Format: dd/mmm/yyyy Tab stop: Yes Locked: Yes staffID ( Text Box) Name: txtStaffID Tab stop: No Locked: Yes Expence ( Text Box) Name: txtExpence Format:Currency Tab stop: Yes Locked: No Description ( Text Box) Name: txtDescrip Tab stop: Yes Locked: No Expence List ( List Box) Name: LstExpence Row source :SELECT ExpenseNo AS [No], Expense, Description FROM tbExpense ORDER BY ExpenseNo;
Room M1 Group 5
Column count:3 Column widths :1,1,1 Column Head: Yes Tab stop: Yes Locked: No Expence Amount ( Text Box) Name: txtAmountExpense Format:Currency Tab stop: Yes Locked: No Staff Amount ( Text Box) Name: txtStaffAmount Format:Currency Tab stop: Yes Locked: No Product Amount ( Text Box) Name: txtAmoutPro Format:Currency Tab stop: Yes Locked: No Total Amount ( Text Box)
Name: txtTotalAmount Format:Currency Tab stop: Yes Locked: No From ( Text Box) Name: txtFrom
70
Room M1 Group 5
Format:dd/mmm/yyyy Tab stop: Yes Locked: No To ( Text Box) Name: txtTo Format:dd/mmm/yyyy Tab stop: Yes Locked: No Expences List ( List Box) Name: LstExpence1 Row source : Row source Type:Table/Query Column count:3 Column widths :1,1,1 Column Head: Yes Tab stop: Yes Locked: No Staffs List ( List Box) Name: LstStaff Row source Type:Table/Query Column count:4 Column widths :1.5";1";1";1" Column Head: Yes Bound Column:1 Tab stop: Yes Locked: No Products List ( List Box) Name: LstProduct
71
Room M1 Group 5
Row source : Row source Type:Table/Query Column count:4 Column widths :1.5";1";1";1" Column Head: Yes Bound Column:1 Tab stop: Yes Locked: No New Button: Name: cmdNew Caption :&New Save Button: Name: cmdSave Caption :&Save Delete Button: Name: cmdDelete Caption :D&elete Search Button: Name: cmdsearch Caption :&Search Close Button: Name: cmdClose Caption :C&lose
Property Form_Load ( Event) .On load [sub Procedure]: Private Sub Form_Load() 'DoCmd.Maximize Dim stSQL As String
Room M1 Group 5 72
stSQL = "Select ExpenseNo as No ,Expense, Description from tbExpense order by ExpenseNo" LstExpense.RowSource = stSQL txtStaffID.value = sid txtStaffID.Locked = True txtExpenseNo.Locked = True txtExpenseDate.Locked = True Call ClearControl(Me) End Sub -------------------------------------------------------------------------------- Property New Button: On click[event procedure]: Private Sub CmdNew_Click() Call ClearControl(Me) Dim i As Integer, index As Integer, n As Integer StExp = "New" txtStaffID.value = sid txtStaffID.Locked = True txtExpenseDate.value = Date txtExpenseNo = AutoNumber("tbExpense", "ExpenseNo") cmdSave.Enabled = True End Sub --------------------------------------------------------------------------------- Property Save Button: On click[event procedure]: Private Sub cmdSave_Click() Dim chk As Boolean chk = CheckNull(txtExpenseDate, txtStaffID, txtExpense, txtDescrip)
Room M1 Group 5 73
If chk = True Then Exit Sub Set db = CurrentDb() If StExp = "New" Then txtExpenseNo = AutoCompleteNum("tbExpense", "ExpenseNo") Call AddNewRecord("tbExpense", txtExpenseNo, txtExpenseDate, txtStaffID.value, txtExpense, txtDescrip) MsgBox "Inserted Completely", vbInformation, "Information" LstExpense.Requery ElseIfStExp = "Old" Then Call EditRecord("tbExpense", "ExpenseNo", txtExpenseNo, txtExpenseDate, txtStaffID, txtExpense, txtDescrip) MsgBox "Updated Completely", vbInformation, "Information" End If Call ClearControl(Me) Call Form_Load End Sub -------------------------------------------------------------------------------------- Property Delete Button: On click:[event procedure]: Private Sub CmdDelete_Click() Set db = CurrentDb() db.Execute "Delete from tbExpense where ExpenseNo=" &txtExpenseNo LstExpense.Requery End Sub -------------------------------------------------------------------------------------------- Property Search Button:
Room M1 Group 5
On click:[event procedure]:
74
Private Sub cmdSearch_Click() Dim sd, st Dim i As Integer, total As Currency, total1 As Currency, total2 As Currency sd = txtFrom st = txtTo If IsNull(sd) Then MsgBox "Please input From Date!",vbInformation, "Information" txtFrom = Null txtFrom.SetFocus ElseIfIsNull(st) Then MsgBox "Please input To date! ",vbInformation, " Information" txtTo.value = Null txtTo.SetFocus Else sd = "#" &sd& "#" st = "#" &st& "#" lstExpense1.RowSource = " SelectDescription,Expense,ExpenseDate From tbExpense e Inner join tbStaff s on s.StaffID=e.staffID where ExpenseDate Between " &sd& " And " &st& " Order by Expense DESC" For i = 1 To lstExpense1.ListCount - 1 total2 = total2 + lstExpense1.Column(1, i) Next LstStaff.RowSource = "SELECT StaffName, Gender, Position, Salary FROM tbStaff Where HireDate Between " &sd& " And " &st& " Order By Salary DESC" For i = 1 ToLstStaff.ListCount - 1 total = total + LstStaff.Column(3, i) Next
Room M1 Group 5
75
LstProduct.RowSource = "SELECT ProductName, ImportDate, p.Quantity, p.UnitPrice, (p.Quantity*p.UnitPrice) AS Amount From tbSupplier l Inner join (tbStaff s Inner join (tbImport i inner join (tbImportDetail d Inner join (tbProduct p inner join tbCategory c on p.CategoryID=c.CategoryID) on p.ProductID=d.ProductID) on d.importID=i.ImportID) on s.StaffID=i.StaffID) on i.SupID=l.SupID WhereImportDate Between " &sd& " And " &st& " Order by Amount" For i = 1 ToLstProduct.ListCount - 1 total1 = total1 + LstProduct.Column(3, i) Next txtStaffAmount.value = total txtAmoutPro.value = total1 txtAmountExpense.value = total2 txtTotalAmount = (total + total1 + total2) End If End Sub ------------------------------------------------------------------------------------------------------ Property List Expence: On click:[event procedure]: Private Sub LstExpense_Click() stSQL = "Select * From tbExpense Where ExpenseNo=" &LstExpense.Column(0) Set db = CurrentDb() Set rs = db.OpenRecordset(stSQL) txtExpenseNo.value = rs(0) txtExpenseDate.value = rs(1) txtStaffID.value = rs(2) txtExpense.value = rs(3) txtDescrip.value = rs(4) StExp = "Old"
Room M1 Group 5 76
cmdSave.Enabled = True End Sub ----------------------------------------------------------------------------------------Function Auto Module Option Compare Database Option Explicit Dim db As DAO.Database, rs As DAO.Recordset Dim stSQL As String, StExpAs String Property FuntionDisplay() on Click:[sub procedure]: Private Sub display() Set db = CurrentDb() Set rs = db.OpenRecordset("tbExspense") With rs txtExpenseNo.value = rs(0) txtExpenseDate.value = rs(1) txtStaffID.value = rs(2) txtExpense.value = rs(3) txtDescrip.value = rs(4) Exp = "Old" End With End Sub ---------------------------------------------------------------------------8. Form Supplier SupplierID ( Text Box) Name: txtSupID Format: 0000 Lock: Yes
Room M1 Group 5 77
Name: txtSupName Name: txtSupPhone Input Mask: (000) 000 0009 SuppliersAddress( Text Box) Update Button: Name: txtSupAddress Name: cmdUpdate Caption:&Update Close Button: Name: cmdClose Caption:C&lose List Supplier ( List Box) Name: lstSuplist Row source Type: Table/Query Bound Column: 1 Column Count: 2 Column Width: 0;1 Multi Select: None
a. Property Form ( Event) Private Sub Form_Load() 'DoCmd.Maximize Dim st As String st = " select supid,supname from tbsupplier order by supid" LstSupList.RowSource = st
Room M1 Group 5 78
End Sub -------------------------------------------------------------------------------b. Property Update Button . On Click Private Sub cmdUpdate_Click() Dim db As DAO.Database Dim id As Integer Dim chk As Boolean, st As String Dim n, p, a chk = CheckNull(TxtSupName, TxtSupPhone, TxtSupaddress) If chk = True Then Exit Sub id = txtSupID.value n = TxtSupName.value p = TxtSupPhone.value a = TxtSupaddress.value n = StrConv(n, vbProperCase) n = "'" &Replace(n, "'", "''") & "'" p = "'" & p & "'" a = "'" & a & "'" Set db = CurrentDb()
Room M1 Group 5 79
db.Execute "update tbsupplier set supname=" & n & ",supphone=" & p & ", supaddress=" & a & " where supid=" & id MsgBox "Update has been saved already!",vbInformation, "Information" LstSupList.Requery Call ClearControl(Me) End Sub ----------------------------------------------------------------------------------------------C . Property List Product . On Click:[Sub Procedure]: Private Sub LstSupList_Click() Dim stSQL As String Dim db As DAO.Database Dim rs As DAO.Recordset stSQL = "select *from tbsupplier where supid=" &LstSupList.value Set db = CurrentDb() Set rs = db.OpenRecordset(stSQL) txtSupID.value = rs(0) TxtSupName.value = rs(1) TxtSupPhone.value = rs(2) TxtSupaddress.value = rs(3)
Room M1 Group 5
80
End Sub --------------------------------------------------------------------------------------d. Property Button Search: OnClick_KeyUP[Sub Procedure]: Private Sub TxtSearch_KeyUp(KeyCode As Integer, Shift As Integer) Dim st As String, id As String st = "select supid,supname from tbsupplier where supname like'" &txtSearch.Text& "*' order by supname" LstSupList.RowSource = st If LstSupList.ListCount = 0 Then Call Clear1(Me) Exit Sub End If LstSupList.Selected(0) = True Call LstSupList_Click End Sub -------------------------------------------------------------------------------e. Property Update Button . On Click:[event Procedure]:
End Sub
9. Form Import ImportID ( Text Box) Name: txtImportId Tab stop: Yes Locked: No ImportDate ( Text Box) Name: txtImportDate Format: dd/mmm/yyyy Tab stop: Yes Locked: No StaffID ( Text Box) Name: txtStaffID Format: 0000 Tab stop: No Locked: yes SupplierID ( Text Box) Name: txtSupID Tab stop: Yes Locked: Yes SupplierName ( Text Box)
Name: txtSupName
Room M1 Group 5 82
Name: txtSupPhone Input Mask: (000) 000 0009 SuppliersAddress( Text Box) List Import ( List Box) Name: txtSupAddress Name: LstImport column count : 5 Column widths: 2";2";2";1.5";1.5";1" Column Head :yes Tab stop: Yes Locked: No Category ( Combo Box)
Name: cboCategory Row source: Row source Type: Table/Query ProductName ( Combo Box) Name: cboProductName Row Source Type:Table/Query Lock :No Tab stop :yes Quantities ( Text Box) Name: txtQty Lock :No Tab stop :yes Unitprice ( Text Box) Name: txtUnitprice Lock :No
Room M1 Group 5 83
Tab stop :yes Amount ( Text Box) Name: txtAmount Lock : Yes Tab stop :yes ExchangRate ( Text Box) Name: txtExchageRate Formate:#,##0.00" R" Lock : No Tab stop :yes TotalAmount ( Text Box) Name: txtTotalAmount Lock : Yes Tab stop :yes New Button: Name: cmdNew Caption :&New Save Button: Name: cmdSave Caption :&Save Old Button:
Name: cmdNewSub Caption :&Old Close Button: Name: cmdClose Caption :C&lose Add Button:
84
Room M1 Group 5
Name: cmdAdd Caption :&Add Remove Button: Name: cmdRemove Caption :R&emove
--------------------------------------------------------------- Property Add Button On Click: [Event Procedure]: Private Sub CmdAdd_Click() Dim pn As String, c As String, Q As Integer, U As Currency Dim a As Currency, chk As Boolean Dim value As String chk = CheckNull(CboCategory, cboProductName, txtQty, txtUnitPrice) If chk = True Then Exit Sub If CheckListProduct(cboProductName.value) = True Then MsgBox "This Product already exist!",vbInformation, "Information" cboProductName.SetFocus Exit Sub End If If IsNull(txtAmount.value) Then Call txtAmount_GotFocus pn = cboProductName.value c = CboCategory.value Q = txtQty.value U = txtUnitPrice.value a = txtAmount.value value = pn& ";" & c & ";" & Q & ";" & U & ";" & a LstImport.AddItem value
Room M1 Group 5 85
Call CalculateTotalAmount Call ClearCtr(CboCategory, cboProductName, txtQty, txtUnitPrice, _ txtAmount) CboCategory.SetFocus End Sub ---------------------------------------------------------------------- Property SupplierName(Combo Box) After Update: [Event Procedure]: Private Sub cboSupName_AfterUpdate() Dim rs As DAO.Recordset If cboSupName.ColumnCount = 1 Then Exit Sub stSQL = "Select * From tbSupplier Where SupID=" _ &cboSupName.Column(0) Set db = CurrentDb() Set rs = db.OpenRecordset(stSQL) txtSupID.value = rs(0) txtAddress.value = rs(2) txtPhone.value = rs(3) rs.Close Set db = Nothing End Sub ----------------------------------------------------------------------- Property ProductName(Combo Box) On Get Focus: [Event Procedure]: Private Sub cboProductName_GotFocus() Dim c c = CboCategory.value
Room M1 Group 5 86
If IsNull(c) Then MsgBox "Please, Input or select one Category!", _ vbInformation, "Information" CboCategory.SetFocus Exit Sub End If stSQL = "Select ProductName From tbProduct Where Category='" _ & c & "' Order ByProductName" cboProductName.RowSource = stSQL End Sub -----------------------------------------------------------------------Function CheckProduct(pn As String) As Boolean Dim db As DAO.Database, rs As DAO.Recordset stSQL = "Select ProductID From TbProduct Where ProductName='" _ &pn& "'" Set db = CurrentDb() Set rs = db.OpenRecordset(stSQL) With rs If .RecordCount> 0 Then pid = .Fields(0) CheckProduct = True Else pid = AutoNumber("tbProduct", "ProductID") CheckProduct = False End If .Close End With
Room M1 Group 5 87
--------------------------------------------------------------------------------- Property Save Button On Click: [Event Procedure]: Private Sub cmdSave_Click() Dim chk As Boolean, i As Integer Dim p As String, c As String Dim Q As Integer, U As Currency, a As Currency chk = CheckNull(txtImportDate, txtSupID, cboSupName, txtAddress, txtPhone) If chk = True Then Exit Sub If LstImport.ListCount = 0 Then MsgBox "Please, Input Imported Products Information!",vbInformation, "Information" CboCategory.SetFocus Exit Sub End If chk = CheckNull(txtExchangeRate, txtTotalAmount) If chk = True Then Exit Sub txtExchangeRate.SetFocus If stSup = "New" Then Call AddNewRecord("tbSupplier", txtSupID.value, _ cboSupName.value, txtAddress.value, txtPhone.value) End If Call AddNewRecord("tbImport", txtImportID.value, txtImportDate.value, _ txtSupID.value, txtStaffID.value, txtTotalAmount.value, txtExchangeRate.value) With LstImport For i = 1 To .ListCount - 1 p = .Column(0, i) c = .Column(1, i)
Room M1 Group 5 88
Q = .Column(2, i) U = .Column(3, i) a = .Column(4, i) If CheckProduct(p) = True Then Set db = CurrentDb() db.Execute "Update tbProduct Set UnitPrice=" & "(Quantity*UnitPrice +" & Q * U & ")/(Quantity+" & Q & "), Quantity=Quantity+" & Q & " Where ProductID=" &pid Else Call AddNewRecord("tbProduct", pid, p, Q, U, c) End If Call AddNewRecord("tbImportDetail", txtImportID.value, _ pid, Q, U, a) Next .RowSource = "ProductName;Categories;Quantities;UnitPrice;Amount" End With Call ClearControl(Me) End Sub Properties Form Load . On Load: [Event Procedure]: Private Sub Form_Load() DoCmd.Maximize cmdNew.SetFocus Call EnabledButton(False) Call ClearControl(Me) End Sub
Room M1 Group 5 89
--------------------------------------------------------------------------------- Properties Category . OnGotfocus: [Event Procedure]: Private Sub cboCategory_GotFocus() stSQL = "Select Distinct category From tbProduct order by Category" CboCategory.RowSource = stSQL End Sub --------------------------------------------------------------------------------- Properties New Button . OnClick : [Event Procedure]: Private Sub cmdNew_Click() Dim id As Long, st As String Call ClearControl(Me) LstImport.RowSource = "ProductName;Categories;Quantity;Unitprice;Amount" id = Auto("tbImport", "ImportID") txtImportID.value = id txtStaffID.value = sid txtImportDate.value = Date txtStaffID.Locked = True Call EnabledButton(True) cmdNewSup.Caption = "Old" cmdNewSup.SetFocus Call cmdNewSup_Click
Room M1 Group 5 90
End sub
Properties NewSup Button . OnClick : [Event Procedure]: Private Sub cmdNewSup_Click() If cmdNewSup.Caption = "New" Then cmdNewSup.Caption = "Old" cboSupName.ColumnCount = 1 cboSupName.RowSourceType = "Value List" cboSupName.AllowValueListEdits = False cboSupName.RowSource = "" cboSupName.ColumnWidths = "1 in" cmdNewSup.SetFocus txtSupID.value = AutoNumber("tbSupplier", "SupID") Call LockedControl(False) Call TabstopControl(True) Call ClearCtr(cboSupName, txtAddress, txtPhone) stSup = "New" ElseIfcmdNewSup.Caption = "Old" Then
Room M1 Group 5 91
Call ClearCtr(txtSupID, cboSupName, _ txtAddress, txtPhone) cmdNewSup.Caption = "New" cboSupName.RowSourceType = "Table/Query" cboSupName.ColumnCount = 2 cboSupName.ColumnWidths = "0 in;1 in" stSQL = "Select SupID, SupName From tbSupplier Order By SupName" cboSupName.RowSource = stSQL Call LockedControl(True) Call TabstopControl(False) stSup = "Old" End If End Sub --------------------------------------------------------------------------------- Properties Amount . OnGotFocus: [Event Procedure]: Private Sub txtAmount_GotFocus() Dim Q As Integer, U As Currency Dim chk As Boolean chk = CheckNull(txtQty, txtUnitPrice)
Room M1 Group 5 92
If chk = True Then Exit Sub Q = txtQty.value U = txtUnitPrice.value txtAmount.value = Q * U txtAmount.Locked = True cmdAdd.Enabled = True cmdAdd.SetFocus End Sub --------------------------------------------------------------------------------- Properties Quantity . OnKey_Press: [Event Procedure]: Private Sub txtQty_KeyPress(KeyAscii As Integer) Static i% If KeyAscii = Asc(".") And i = 0 Then i=1 Exit Sub End If If KeyAscii = vbKeyBackAnd i = 1 Then i=0 Exit Sub End If If KeyAscii>= vbKey0 And KeyAscii<= vbKey9 Or _ KeyAscii = vbKeyBack Then Exit Sub
Room M1 Group 5 93
Else KeyAscii = 0 MsgBox "You can not input character "&vbCrLf& "Please, input number.", vbInformation, "Information" End If --------------------------------------------------------------------------------- Properties Unitpirce . OnKey_Press: [Event Procedure]: Private Sub txtUnitprice_KeyPress(KeyAscii As Integer) Static i% If KeyAscii = Asc(".") And i = 0 Then i=1 Exit Sub End If If KeyAscii = vbKeyBackAnd i = 1 Then i=0 Exit Sub End If If KeyAscii>= vbKey0 And KeyAscii<= vbKey9 Or _ KeyAscii = vbKeyBack Then Exit Sub Else
Room M1 Group 5 94
MsgBox "You can not input character "&vbCrLf& "Please, input number.",
10. Form Rent RentID ( Text Box) Name: txtRentID Tab stop: Yes Lock: No RentDate ( Text Box) Name: txtRentDate Format : dd/mmm/yyyy Tab stop: Yes Lock: No ExpireDate ( Text Box) Name: txtExpireDate Format : dd/mmm/yyyy Tab Stop : Yes Locked : No StaffID ( Text Box) Name: txtStaffID Format : 000000 Tap Stop : Yes Lock : Yes CustomerID ( Text Box) Name: txtCusID Tap Stop : Yes
95
Room M1 Group 5
Lock : No
Name: cboCusName Row source Type : Table/Query Column count: 2 Column Head: No Bound Column: 1 Address ( Text Box) Name : txtAddress ContactPhone ( Text Box) Name : txtPhone Input Mask: (000)-000-0009
Name: cboStoreName Row source Type : Table/Query Row source :SELECT DISTINCT StoreName FROM tbStore WHERE
status='Available' ORDER BY StoreName;
Room M1 Group 5
Column count: 1 Column Head: No Bound Column: 1 Floor ( Text Box) Name : txtFloor Tap Stop : Yes
96
Room M1 Group 5
Lock : Yes StoreType ( Text Box) Name : txtStoreType Tap Stop : No Lock : Yes Status ( Text Box) Name : txtStatus Tap Stop : No Lock : Yes UnitPrice ( Text Box) Name : txtUnitPrice Format : $#,##0.00 Tap Stop : No Lock : Yes Discount ( Text Box) Name : txtDiscount Format: General Number Tap Stop : Yes Lock : No Amount ( Text Box) Name : txtAmount Format : $#,##0.00 Tap Stop : Yes Lock : Yes Lock : No ExchangRate ( Text Box) Name : txtExRate Format : #,##0.00" R"
97
Tap Stop : Yes Lock : No Pay Amount ( Text Box) Name : txtPayAmount Format : Currency Tap Stop : Yes Lock : No Total Amount ( Text Box) Name : txtTotalAmount Format : Currency Tap Stop : Yes Lock : No Remaining Amount ( Text Box) Name : txtReAmount Format : Currency Tap Stop : Yes Lock : Yes List RentImport ( List Box) Name: lstRentImport Row source : StoeName;StoreType;Floor;Status;Discount;Amount Row source Type: Value List Bound Column: 1 Column Count: 6 Column Width: 1.5";2";1.5";2";1.5";2" Multi Select: None
b. Property Add Button .On Click: [Event Procedure] Private Sub CmdAdd_Click() Dim sn As String, st As String, fl As String, sa As String Dim r As String, un As Currency, dis As Integer Dim chk As Boolean, value As String, am As Currency chk = CheckNull(cboStoreName, txtFloor, txtStoreType, txtDiscount) If chk = True Then Exit Sub If IsNull(txtAmount.value) Then Call txtAmount_GotFocus sn = cboStoreName.value st = txtStoreType.value fl = txtFloor.value un = txtUnitPrice.value dis = txtDiscount.value am = txtAmount.value Set db = CurrentDb() db.Execute "Update tbstore set status='Unavailable' where storename='" & cboStoreName.value & "'" value = sn & ";" & st & ";" & fl & ";" & un & ";" & dis & ";" & am lstRentImport.AddItem value Call CalculateTotalAmount
Room M1 Group 5
99
Call ClearCtr(cboStoreName, txtFloor, txtStoreType, txtStatus, txtUnitPrice, txtDiscount, txtAmount) cboStoreName.SetFocus End Sub ---------------------------------------------------------------
c. Property Remove Button .On Click: [Event Procedure] Private Sub cmdRemove_Click() Set db = CurrentDb() db.Execute "Update tbstore set status='Available' where storename='" &lstRentImport.Column(0) & "'" Call RemoveListItem(lstRentImport) Call CalculateTotalAmount cboStoreName.SetFocus End Sub ---------------------------------------------------------------
d. Property New Customer Button .On Click: [Event Procedure] Private Sub cmdNewCustomer_Click() If cmdNewCustomer.Caption = "New C&ustomer" Then cmdNewCustomer.Caption = "Old C&ustomer" cboCusName.ColumnCount = 1 cboCusName.RowSourceType = "Value List" cboCusName.AllowValueListEdits = False cboCusName.RowSource = ""
Room M1 Group 5 100
cboCusName.ColumnWidths = "1 in" cboCusName.SetFocus txtCusID.value = AutoNumber("tbCustomer", "CusID") Call LockedControl(False) Call TabstopControl(True) Call ClearCtr(cboCusName, txtAddress, txtPhone) stCustomer = "New C&ustomer" ElseIf cmdNewCustomer.Caption = "Old C&ustomer" Then Call ClearCtr(txtCusID, cboCusName, txtAddress, txtPhone) cmdNewCustomer.Caption = "New C&ustomer" cboCusName.RowSourceType = "Table/Query" cboCusName.ColumnCount = 2 cboCusName.ColumnWidths = "0 in ; 1 in" stsQL = "Select CusID, CusName from tbCustomer order by CusName" cboCusName.RowSource = stsQL Call LockedControl(True) Call TabstopControl(False) stCustomer = "Old C&ustomer" End If End Sub --------------------------------------------------------------e. Property New Button .On Click: [Event Procedure] Private Sub cmdNew_Click() Dim id As Long, st As String Dim rd lstRentImport.RowSource = "StoreName;StoreType;Floor;UnitPrice;Discount;Amount"
Room M1 Group 5 101
Call ClearControl(Me) txtRentDate.value = Date rd = txtRentDate.value txtExpireDate.value = DateAdd("m", 12, rd) txtExpireDate.Locked = True cboCusName.SetFocus id = Auto("tbRent", "RentID") txtRentID.value = id txtStaffID.value = sid txtStaffID.Locked = True Call EnableButton(True) cmdNewCustomer.Caption = "Old C&ustomer" Call cmdNewCustomer_Click End Sub --------------------------------------------------------------f. Property New Button .On Click: [Event Procedure] Private Sub cmdSave_Click() Dim chk As Boolean, i As Integer Dim sn As String, st As String, fl As Integer Dim U As Currency, a As Currency Dim d As Integer, id As Integer chk = CheckNull(txtExpireDate, cboCusName, txtAddress, txtPhone) If chk = True Then Exit Sub If lstRentImport.ListCount = 1 Then MsgBox "Please, Input RentDetail Information!", vbInformation, "Information" cboStoreName.SetFocus Exit Sub
Room M1 Group 5 102
End If chk = CheckNull(txtExRate, txtPayAmount) If chk = True Then Exit Sub If stCustomer = "New C&ustomer" Then Call AddNewRecord("tbCustomer", txtCusID.value, cboCusName.value, txtAddress.value, txtPhone.value) End If Set db = CurrentDb() db.Execute "Insert into tbRent values (" & txtRentID.value & ",#" & txtRentDate.value & "#," & txtCusID.value & "," & txtStaffID.value & ",#" & txtExpireDate.value & "#," & txtPayAmount.value & "," & txtTotalAmount.value & "," & txtReAmount.value & "," & txtExRate.value & ")" With lstRentImport For i = 1 To .ListCount - 1 sn = .Column(0, i) st = .Column(1, i) fl = .Column(2, i) U = .Column(3, i) d = .Column(4, i) a = .Column(5, i) Dim rs As Recordset Set db = CurrentDb() Set rs = db.OpenRecordset("Select storeid from tbstore where storename='" & sn & "'") id = rs(0) rs.Close db.Execute "Insert into tbRentDetail values (" & txtRentID.value & "," & id & "," & U & "," & d & "," & a & ")"
Room M1 Group 5 103
Next .RowSource = "StoreName;StoreType;Floor;UnitPrice;Discount;Amount" End With Call ClearControl(Me) End Sub --------------------------------------------------------------g. Property Close Button .On Click: [Event Procedure] Private Sub cmdClose_Click() Set db = CurrentDb() Dim rs As DAO.Recordset, i As Integer If lstRentImport.ListCount <> 0 Then For i = 1 To lstRentImport.ListCount - 1 Set rs = db.OpenRecordset("Select storeid from tbstore where storename='" & lstRentImport.Column(0, i) & "'") db.Execute "Update tbstore set status='Available' where storeid=" &rs(0) rs.Close Next End If Call CloseForm(Me) End Sub 11. Form Payment
Room M1 Group 5
Name: txtExpireDate Format : General Date Tab Stop : Yes Locked : No StaffID ( Text Box) Name: txtStaffID Format : 000000 Tap Stop : Yes Lock : Yes CustomerID ( Text Box) Name: txtCusID Format : 0000 Tap Stop : Yes Lock : No StaffID ( Text Box) Name: txtStaffID Format : 0000 Tap Stop : Yes Lock : No PayAmount ( Text Box)
105
Room M1 Group 5
Name: txtPay Format : Currency Rent Remain ( Text Box) Name: txtRemain Format : $#,##0.00 ExchangRate ( Text Box) Name: txtexchange Format : #,##0.00 Search ( Text Box) List Customer ( List Box) Name: txtSearch Name: lstCustomer Row source Type: Table/Query Bound Column: 1 Column Count: 2 Column Width: 0";1" Multi Select: None Store Name ( Cambo Box) Name: cboStore Row source Type : Table/Query Column count: 2 Column Head: No Bound Column: 1
a. Property Form ( Event) Private Sub Form_Load() DoCmd.Maximize Dim st As String stSQL = "select cusid,cusname from tbcustomer order by cusid"
Room M1 Group 5 106
lstCustomer.RowSource = stSQL txtRentID.Enabled = False txtExpireDate.Enabled = False txtCusID.Enabled = False txtStaffID.Enabled = False End Sub -------------------------------------------------------------b. Property Update Button .On Click: [Event Procedure] Private Sub cmdUpdate_Click() Dim chk As String Dim c, f, py, R, d, e, rd, ex R = txtRentID.value ex = txtExpireDate.value d = txtpaydate.value c = txtCusID.value f = txtStaffID.value e = Txtexchange.value py = TxtPay.value rd = TxtRemain.value chk = CheckNull(txtRentID, TxtPay, txtpaydate, txtCusID, txtStaffID, Txtexchange, TxtRemain) If chk = True Then Exit Sub d = "#" & d & "#" ex = "#" & ex & "#" Set db = CurrentDb() db.Execute "update tbrent set rentdate=" & d & ", expiredate=" & ex & " , cusid=" _
Room M1 Group 5 107
& c & ", staffid=" & f & ", exchangerate=" & e & ", remainamount=" & rd & ",Payamount=" & py & " where rentid=" & R MsgBox "Record has been saved already!", vbInformation, " Information" Call ClearControl(Me) End Sub --------------------------------------------------------------c. Property Print Button .On Click: [Event Procedure] Private Sub cmdPrint_Click() DoCmd.OpenReport " rptpayment", acViewPreview End Sub --------------------------------------------------------------d. Property Close Button .On Click: [Event Procedure] Private Sub cmdClose_Click() Call CloseForm(Me) End Sub 12. Form StoreType TypeID ( Text Box) Name: txtTypeID Format: 0000 Tape Stop : Yes Locked : Yes StoreType ( Combo Box) Name: cboStoreType Row source Type : Table/Query
Room M1 Group 5 108
Column count: 1 Column Head: No Bound Column: 1 UnitPrice ( Text Box) Name : txtUnitPrice Format : Currency Tape Stop : Yes Locked : Yes Search Stores Type ( Text Box) Name: txtInputSearch Tap Stop : Yes Lock : No
Name: lstStore Row source : SELECT StaffID, StaffName FROM tbstaff WHERE StaffName
Like 's*' ORDER BY StaffName;
Row source Type: Table/Query Bound Column: 0 Column Count: 2 Column Width: 0;1 Multi Select: None
a. Property Form ( Event) .On Click: [Event Procedure] Private Sub Form_Load() DoCmd.Maximize Dim stsQL As String
Room M1 Group 5 109
stsQL = "Select TypeID,StoreType from tbStoreType order by TypeID" LstStore.RowSource = stsQL cmdUpdate.Enabled = False End Sub --------------------------------------------------------------b. Property Update Button .On Click: [Event Procedure] Private Sub cmdUpdate_Click() Dim db As DAO.Database If IsNull(cboStoreType.value) Then MsgBox "Please, input Store type!", vbInformation, "Information" cboStoreType.SetFocus ElseIf IsNull(txtUnitPrice.value) Or IsNumeric(txtUnitPrice.value) = False Then MsgBox "Please, input Store price!", vbInformation, "Information" txtUnitPrice.value = Null txtUnitPrice.SetFocus Else Dim Y As Integer Y = MsgBox("Do you want to update?", vbInformation + vbYesNo, "Information") If Y = vbNo Then Exit Sub Set db = CurrentDb() db.Execute " Update tbStoreType set StoreType='" & cboStoreType & "', Unitprice=" & txtUnitPrice.value & " where TypeID= " & txtTypeID.value LstStore.Requery End If End Sub --------------------------------------------------------------Room M1 Group 5 110
c. Property Close Button .On Click: [Event Procedure] Private Sub cmdClose_Click() Call CloseForm(Me) End Sub --------------------------------------------------------------------------13. Form Store StoreNo ( Text Box) Name: txtStoreID Tab stop: Yes Locked: Yes StoreName ( Text Box) Name: txtStoreName Tab stop: Yes Lock: No CboTypeID ( Combo Box) Name: cboTypeID Row source Type: Table/Query Column count: 1 Column Head: No Bound Column: 1 StoreFloor ( Combo Box) Name: cboFloor Row source Type : Table/Query Row source : SELECT DISTINCT TypeID FROM tbStoreType ORDER BY TypeID; Column count: 1 Column Head: No Bound Column: 1
111
Room M1 Group 5
Name: txtStatus Tap Stop : Yes Lock : No Search Stores Name ( Text Box) Name: txtInputSearch Tap Stop : Yes Lock : No Name: lstStore Row source : SELECT storeID AS Expr1, tbStore.StoreNameFROM tbStore
ORDER BY tbStore.StoreName;
Row source Type: Table/Query Bound Column: 1 Column Count: 2 Column Width: 0;1 Multi Select: None
a. Property Form ( Event) Private Sub Form_Load() DoCmd.Maximize Dim stSQL1 As String stSQL1 = "Select storeID, StoreName from tbStore order by StoreName" LstStore.RowSource = stSQL1 txtStoreID.Locked = True cmdNew.SetFocus cmdSave.Enabled = False Call ClearControl(Me)
Room M1 Group 5 112
End Sub b. Property New Button .On Click: [Event Procedure] Private Sub cmdNew_Click() Call ClearControl(Me) txtStoreID = AutoCompleteNum("tbStore", "StoreID") txtStoreName.SetFocus cmdSave.Enabled = True ststore = "New" End Sub --------------------------------------------------------------c. Property List Store .On Click: [Event Procedure] Private Sub LstStore_Click() stsQL = "Select s.StoreID,s.StoreName,t.TypeID,s.StoreFloor,s.Status From tbStore s Inner join tbStoreType t on s.TypeID=t.TypeID Where StoreID=" & LstStore.Column(0) Set db = CurrentDb() Set rs = db.OpenRecordset(stsQL) txtStoreID.value = rs(0) txtStoreName.value = rs(1) CboTypeID.value = rs(2) cboFloor.value = rs(3) txtStatus.value = rs(4) ststore = "Old" cmdSave.Enabled = True End Sub --------------------------------------------------------------Room M1 Group 5 113
d. Property Save Button .On Click: [Event Procedure] Private Sub cmdSave_Click() Dim chk As Boolean chk = CheckNull(txtStoreName, CboTypeID, cboFloor, txtStatus) If chk = True Then Exit Sub If ststore = "New" Then txtStoreID = AutoCompleteNum("tbStore", "StoreID") Call AddNewRecord("tbStore", txtStoreID, txtStoreName, CboTypeID, cboFloor, txtStatus) MsgBox "Inserted Completely", vbInformation, "Information" LstStore.Requery ElseIf ststore = "Old" Then Call EditRecord("tbStore", "StoreID", txtStoreID.value, txtStoreName.value, CboTypeID.value, cboFloor.value, txtStatus.value) MsgBox "Updated Completely", vbInformation, "Information" End If Call ClearControl(Me) Call Form_Load End Sub --------------------------------------------------------------e. Property Delete Button .On Click: [Event Procedure] Private Sub cmdDelete_Click() Dim Y As Byte Set db = CurrentDb() Y = MsgBox("Do you want to delete?", vbInformation + vbYesNo, "Information")
Room M1 Group 5 114
If Y = vbNo Then Exit Sub db.Execute "Delete from tbStore where StoreID=" & txtStoreID MsgBox "Delete completly" LstStore.Requery End Sub -------------------------------------------------------------f. Property Text box InputSearch .On Key UP: [Event Procedure] Private Sub txtInputSearch_KeyUp(KeyCode As Integer, Shift As Integer) stsQL = "Select StoreID, StoreName From tbstore " & " Where StoreName Like '" & txtInputSearch.Text & "*' Order By StoreName" LstStore.RowSource = stsQL If LstStore.ListCount = 0 Then Call ClearControl(Me) txtInputSearch.SetFocus txtInputSearch.SelStart = Len(txtInputSearch.Text) Exit Sub End If LstStore.Selected(0) = True Call LstStore_Click cmdSave.Enabled = True End Sub -------------------------------------------------------------- Properties InputSearch . After Update: [Event Procedure] Private Sub txtInputSearch_AfterUpdate() txtInputSearch.value = Null txtInputSearch.SetFocus
Room M1 Group 5 115
End Sub g. Property Close Button .On Click: [Event Procedure] Private Sub cmdClose_Click() Call CloseForm(Me) End Sub 14. Button BackUp Form main Module Envent
a. Module Function ZipandBackUpDb() On Error GoTo Err_BackUpDb 'this line is very important to handle files 'it's very necessary to add the "Microsoft scripting runtime" reference from the tools->references in the VBA window Dim fso As FileSystemObject Dim sSourcePath As String Dim sSourceFile As String Dim sBackupPath As String Dim sBackupFile As String Dim strFileName As String Dim sBackupFolder As String Dim sFinalPath As String 'this will show you the dialog box to select the file you want to backup strFileName = " D:\All Database\How to Backup.accdb"
Room M1 Group 5 116
If Not strFileName = "None Selected" Then sSourcePath = strFileName Else MsgBox " BackUp Action cancelled. Database not backed up. ", vbCritical, " BackUp Failure" Exit Function End If 'this will create a temporary directory on "C:\" and will call it Temp if there is no a temp directory If Not Dir("C:\Temp", vbDirectory) <> "" Then MkDir "C:\Temp" sBackupPath = "C:\Temp\" sBackupFile = "BackUp.mdb" 'this will show you the dialog box to select where you want to save the zipped file sBackupFolder = " D:\All Database" If Not sBackupFolder = "None Selected" Then sFinalPath = sBackupFolder & "\" Else MsgBox " BackUp Action cancelled. Database not backed up. ", vbCritical, " BackUp Failure" Exit Function End If 'this will make the cursor hour glass shape Screen.MousePointer = 11
Room M1 Group 5
117
Set fso = New FileSystemObject fso.CopyFile sSourcePath, sBackupPath & sBackupFile, True Set fso = Nothing Dim sWinZip As String Dim sZipFile As String Dim sZipFileName As String Dim sFileToZip As String
sWinZip = "C:\Program Files\WinZip\WinZip32.exe" 'Location of the WinZip program 'here you can change the name of the file. sZipFileName = Left(sBackupFile, InStr(1, sBackupFile, ".", vbTextCompare) 1) & Format(Date, "dd-mm-yyyy") & "-" & Format(Time, "hh-mmAMPM") & ".zip" sZipFile = sBackupPath & sZipFileName sFileToZip = sBackupPath & sBackupFile Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide) pause (3) Set fso = New FileSystemObject fso.CopyFile sBackupPath & sZipFileName, sFinalPath & sZipFileName, True Set fso = Nothing
Room M1 Group 5
118
Screen.MousePointer = 0 MsgBox "Backup was successful. " & "The backup file is named: " & Chr(13) & " " & sFinalPath & sZipFileName, vbInformation, "Backup Completed" If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile) If Dir(sBackupPath & sZipFileName) <> "" Then Kill (sBackupPath & sZipFileName) Exit_BackUpDb: Exit Function Err_BackUpDb: If Err = 5 Then 'Invalid procedure call or argument MsgBox "Disk is full! Can not move the zip file to the Drive. Please move the " & sZipFile & " file to a safe location.", vbCritical, " BackUp Failure" If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile) If Dir(sBackupPath & sZipFileName) <> "" Then Kill (sBackupPath & sZipFileName) Exit Function ElseIf Err = 53 Then 'File not found MsgBox "Source file can not be found!" & vbNewLine & sZipFileName, vbCritical, " BackUp Failure" Exit Function ElseIf Err = 71 Then 'Disk not ready
Room M1 Group 5 119
If Dir(sZipFile) <> "" Then Kill sZipFile If Dir(sFileToZip) <> "" Then Kill sFileToZip MsgBox "Please insert a diskette in Drive and try again!", vbCritical, " BackUp Failure" Exit Function ElseIf Err = -2147024784 Then 'Method 'CopyFile' of object 'IFileSystem3' failed MsgBox "File is to large to be zipped to the Drive!" & vbNewLine & sZipFile, vbCritical, " BackUp Failure" Exit Function Else MsgBox Err.Number & " - " & Err.Description, , " BackUp Failure" Resume Exit_BackUpDb End If End Function Private Sub pause(n As Integer) Dim PauseTime, Start PauseTime = n ' Set duration in seconds Start = Timer ' Set start time. Do While Timer < Start + PauseTime DoEvents ' Yield to other processes. Loop End Sub b. Event on click Private Sub Command0_Click() Dim st As String
Room M1 Group 5 120
st = ZipandBackUpDb() End Sub 15. Form User txtUserID ( Text Box) Name : txtUSerID Tap Stop : No Lock : Yes cboStaffID ( combo Box) Name : cboStaffID Tap Stop : Yes Lock : No UserName ( Text Box) Name : txtUserName Tap Stop : Yes Lock : No Usepassword ( Text Box) Name : txtUserPass Tap Stop : Yes Lock : No Confirm ( Text Box) Name : txtConfirm Tap Stop : Yes Lock : No Search Stores Name ( Text Box) Name: txtInputSearch Tap Stop : Yes Lock : No
Room M1 Group 5
121
Name: lstUser Row source Type: Table/Query Bound Column: 1 Column Count: 2 Column Width:0;1 Multi Select: None New ( Button) Name : cmdNew Caption: &New Save ( Button) Name : cmdSave Caption: &Save Change( Button) Name : cmdChange Caption: &Change Close ( Button) Name : cmdCLose Caption: &Close Delete ( Button) Name : cmdDelete Caption: &Delete Private Sub Form_Load() Dim st1 As String DoCmd.Maximize st1 = "Select UserID, UserName From tbUser order by UserName " LstUser.RowSource = st1
Room M1 Group 5
122
txtUserID.Locked = True cmdNew.SetFocus cboStaffID.Enabled = False cmdSave.Enabled = False cmdDelete.Enabled = False txtCon = txtPass txtCon.Visible = False Call ClearCtr(txtUserID, txtUserName, txtPass, txtCon, cboStaffID) ' ClearControl (Me) End Sub b. Property New Button . On Click Private Sub cmdNew_Click() Call ClearCtr(txtUserID, txtUserName, txtPass, cboStaffID) txtUserID = AutoCompleteNum("tbUser", "UserID") stUser = "New" cboStaffID.Enabled = True cmdSave.Enabled = True cmdSave.Caption = "&Save" End Sub ------------------------------------------------------------------c. Property Save Button . On Click Private Sub cmdSave_Click() Dim u As Integer Dim us, st, p, con us = txtUserName.value p = txtPass.value
Room M1 Group 5 123
st = cboStaffID.value p = txtPass.value con = txtCon.value If IsNull(us) Or IsNumeric(us) = True Then MsgBox "Please, input UserName", vbInformation, "Information" txtUserName.value = Null txtUserName.SetFocus ElseIf IsNull(p) Then MsgBox "Please, input password", vbInformation, "Information" txtPass.SetFocus ElseIf IsNull(con) Or con <> p Then MsgBox "Please,input Confirm Password", vbInformation, "Information" txtCon.value = Null txtCon.SetFocus ElseIf IsNull(st) Then MsgBox "Please, input StaffID", vbInformation, "Information" cboStaffID.value = Null cboStaffID.SetFocus Else If stUser = "New" Then txtUserID = AutoCompleteNum("tbUser", "UserID") Call AddNewRecord("tbUser", txtUserID, txtUserName, txtPass, cboStaffID) MsgBox "Inserted Completely", vbInformation, "Information" LstUser.Requery Call ClearControl(Me) ' ElseIf stUser = "Old" Then
Room M1 Group 5
124
Call EditRecord("tbUser", "UserID", txtUserID, txtUserName, txtPass, MsgBox "Updated Completely", vbInformation, "Information" LstUser.Requery End If Call ClearCtr(txtUserID, txtUserName, txtPass, cboStaffID) Call Form_Load End If
cboStaffID)
End Sub ------------------------------------------------------------------d. Property Delete Button . On Click Private Sub cmddelete_Click() Dim db As DAO.Database Dim Y As Byte Set db = CurrentDb() Y = MsgBox("Do you want to delete?", vbInformation + vbYesNo, "Information") If Y = vbNo Then Exit Sub db.Execute "Delete from tbUser where UserID=" & txtUserID.value MsgBox "Delete completely", vbInformation, " Information" LstUser.Requery 'Call ClearControl(Me) Call ClearCtr(txtUserID, txtUserName, txtPass, txtCon, cboStaffID) End Sub -----------------------------------------------------------------------e. Property Change Button . On Click
Room M1 Group 5 125
Private Sub cmdUpdate_Click() DoCmd.OpenForm ("frmChangePassword") End Sub --------------------------------------------------------------f. Property Change Button . On Click Private Sub cmdClose_Click() Call CloseForm(Me) End Sub ----------------------------------------------------------------------g. Property search . After Update Private Sub txtInputSearch_AfterUpdate() txtInputSearch.value = Null txtInputSearch.SetFocus End Sub -------------------------------------------------------------.Key Down Private Sub txtInputSearch_KeyDown(KeyCode As Integer, Shift As Integer) stSQL = "Select UserID, UserName From tbUser " & " Where UserName Like '" & txtInputSearch.Text & "*' Order By UserName" LstUser.RowSource = stSQL If LstUser.ListCount = 0 Then Call ClearControl(Me) txtInputSearch.SetFocus
Room M1 Group 5 126
txtInputSearch.SelStart = Len(txtInputSearch.Text) Exit Sub End If LstUser.Selected(0) = True End Sub -----------------------------------------------------------------------. On Key presss Private Sub txtInputSearch_KeyPress(KeyAscii As Integer) If KeyAscii >= vbKeyA And KeyAscii <= vbKeyZ Or _ KeyAscii >= Asc("a") And KeyAscii <= Asc("z") Or _ KeyAscii = vbKeyBack Or _ KeyAscii = vbKeyDelete Or _ KeyAscii = Asc(" ") Then Exit Sub Else KeyAscii = 0 MsgBox "You can input number", vbCritical, "Warmming" Beep End If End Sub -----------------------------------------------------------------------h. Property lstUser . On Click Private Sub lstuser_Click() stSQL = "Select * From tbUser Where USerID=" & LstUser.Column(0) Set db = CurrentDb() Set rs = db.OpenRecordset(stSQL) txtUserID.value = rs(0)
Room M1 Group 5 127
txtUserName.value = rs(1) txtPass.value = rs(2) cboStaffID.value = rs(3) stUser = "Old" cmdDelete.Enabled = True ' cmdSave.Enabled = True End Sub ------------------------------------------------------------- Sub Procedure Display Private Sub Display() Set db = CurrentDb() Set rs = db.OpenRecordset("tbStaff") With rs txtUserID = .Fields(0) txtUserName = .Fields(1) txtPass = .Fields(2) cboStaffID = .Fields(3) ststaff = " Old" End With End Sub
Room M1 Group 5
128
16. Form ChangePassword txtUSerID ( Text Box) Name: txtUSerID Format: 0000 txtUSerName ( Text Box) txtOldPass ( Text Box) txtNewPass ( Text Box) txtConfirm ( Text Box) Change ( Button) Name: txtUserName Name: txtOld Name: txtNewpass Name: txtConfirm Name: txtChange Caption: &Change CLose ( Button) Name: txtclose Caption: &close a. Property Form ( Event) Private Sub Form_Load() Dim i As Integer For i = 1 To Form_frmUser.LstUser.ListCount - 1 If Form_frmUser.LstUser.Selected(i) = True Then txtUserID = Form_frmUser.LstUser.Column(0, i) txtName = Form_frmUser.LstUser.Column(1, i) txtUserID.Locked = True
Room M1 Group 5 129
txtName.Locked = True End If Next txtOldPassword.SetFocus End Sub ----------------------------------------------------------------------b. Property New . On Got Focus Private Sub txtNewPassword_GotFocus() Dim i As Integer If IsNull(txtOldPassword) = True Then MsgBox "Please, input your old password!", vbInformation, "Information" txtOldPassword.SetFocus End If For i = 1 To Form_frmUser.LstUser.ListCount - 1 If Form_frmUser.LstUser.Selected(i) = True Then If txtOldPassword <> Form_frmUser.LstUser.Column(2, i) Then MsgBox "Please input your old password again!", vbInformation, "Information" txtOldPassword.SetFocus End If End If Next End Sub
Room M1 Group 5
130
c. Property Change .On Click Private Sub cmdChange_Click() Dim i As Integer If CheckNull(txtOldPassword, txtNewPassword, txtComfirm) = True Then Exit Sub If txtComfirm <> txtNewPassword Then MsgBox "Please cofirm password again!", vbInformation, "Information" txtComfirm.SetFocus Else For i = 1 To Form_frmUser.LstUser.ListCount - 1 If Form_frmUser.LstUser.Selected(i) = True Then Call ChangePassword(i) End If Next MsgBox "Updated completly", vbInformation End If Call ClearControl(Me) End Sub ------------------------------------------------------------------d. Property Close .On Click Private Sub cmdClose_Click() Call CloseForm(Me) End Sub
Room M1 Group 5
131
References
1. 2009-2010 2. Advanced Access 2007 200
Website
www. Totorail.com www.AnswerMicrosoft.com
Room M1 Group 5
132