MACRO
[email protected]
NỘI DUNG
MACRO LÀ GÌ?1
PHÂN LOẠI MACRO2
STANDALONE MACRO3
DATA MACRO4
CONNECTING MACROS TO FORM5
[email protected]
MACRO LÀ GÌ?
Macro là tập hợp các lệnh được định sẵn
Macro có thể liên kết các đối tượng trong CSDL
Macro được dùng khi
Có các hành động thường xuyên lặp lại (tự động hóa
công việc)
Kết hợp các hành động đơn giản
[email protected]
PHÂN LOẠI MACRO
Standalone macro
Là một đối tượng của CSDL
Sau khi được tạo và lưu thì nó xuất hiện trong Navigation
pane
Data macro
Được lưu trữ như một phần của Table
Có thể thiết lập để thực thi macro trước hoặc sau khi một
bản ghi được thêm vào, chỉnh sửa hoặc xóa
Thường dùng để thiết lập Validation rule hoặc default value
Embedded macro
Được lưu trữ như một phần của form hoặc report
Macro chỉ được thực thi khi form hoặc report hoặc một đối
tượng trên form hoặc report chịu tác động của một sự kiện
[email protected]
STANDALONE MACRO
[email protected]
TẠO STANDALONE MACRO
1. Click nút Macro trên Create tab
[email protected]
[email protected]
TẠO STANDALONE MACRO
2. Chọn Action trong khung Add New Action hoặc
Action catalog
[email protected]
TẠO STANDALONE MACRO
3. Nhập đối số cho action
4. Thực thi macro (Run)
[email protected]
MỘT SỐ ACTION THÔNGDỤNG
[email protected]
[email protected]
[email protected]
THIẾT LẬP ĐỐI SỐ CHOACTION
[email protected]
MỘT SỐ THAO TÁC KHI THIẾT KẾMACRO
Di chuyển/ xóa Action
[email protected]
MỘT SỐ THAO TÁC KHI THIẾT KẾMACRO
Copy action
Giữ phím Ctrl, kéo Action đến vị trí mong muốn
Thêm comment
Add new action chọn Comment
[email protected]
SUBMARCOS
Subroutines: a set of actions (commands) with a
name
Subroutines can be performed by calling it using
its name
In Access, subroutines are called submacros
Submacros contain actions or other submacros
[email protected]
CREATE A SUBMACRO
1. Display the Action catalog and the Program Flow
(if they are not displayed)
2. Drag the Submacro to the macro or double click
on the Submacro
3. Type a name for the submacro
4. Enter the submacro’s actions and arguments
[email protected]
[email protected]
[email protected]
[email protected]
AUTORUN MACRO
To create a macro that automatically runs when
the database opens: just name the macro
AutoExec
If you do not want the AutoExec macro to run,
hold down the Shift key while the database is
loading
[email protected]
ASSIGNING MACROS TO KEYS
Create a macro group named AutoKeys
AutoKeys contains submacros with the name of
keys (or key combinations) on the keyboard
Access runs the appropriate submacro when you
press the key
[email protected]
[email protected]
NAME A KEY-ASSIGNMENTMACRO
^ indicate Ctrl key
+ indicate Shiftkey
Put {} around key names that are more than one
letter long
[email protected]
OPENING DB THAT CONTAIN MACROS
[email protected]
CONDITIONAL EXECUTION (IF-THEN
MACRO)
[email protected]
[email protected]
HÀM THƯỜNG DÙNG TRONGBTĐK
MsgBox(msg, type, title)
[email protected]
MSGBOX(MSG, TYPE, TITLE)
[email protected]
HÀM THƯỜNG DÙNG TRONGBTĐK
Dcount(field, domain, criteria)
IsNull(field)
[email protected]
DATA MACRO
[email protected]
TẠO DATAMACRO
Mở table ở chế độ Design view
[email protected]
TẠO DATAMACRO
Lựa chọn event để kích hoạt macro
[email protected]
TẠO DATAMACRO
Thêm action vào macro
[email protected]
XÓA/ĐỔI TÊN DATAMACRO
[email protected]
CHỈNH SỬA MACRO
[email protected]
CHỈNH SỬA MACRO
[email protected]
VÍ DỤ 1
[email protected]
[email protected]
VÍ DỤ 2
[email protected]
[email protected]
DEBUGGING DATA MACROS
Sử dụng USysApplicationLog
[email protected]
[email protected]
VÍ DỤ 3: SYNCHRONIZING DATA
Tự động tính toán lại số lượng hàng trong kho khi
có khách hàng đặt hàng.
Các macro cần thiết
Bảng liên quan: Products và Order Details
Macros:
◦ After Insert: đặt hàng mới
◦ After update: chỉnh sửa đơn hàng cũ
◦ After delete: xóa đơn hàng
[email protected]
TẠO NAMED MACRO
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
CONNECTING MACROS TO
FORMS
[email protected]
EVENT
Control events
Xuất hiện khi thao tác với điều khiển
Ví dụ: On Click, On Change
Section events
Event xảy ra trên header hoặc footer của form
Ví dụ: On Mouse Move, On Click
Form events
Ví dụ: On Open, On Close, On Current, After Update
[email protected]
[email protected]
[email protected]
VÍ DỤ 1: STANDALONE MACRO IN FORMS
[email protected]
Tạo button
bằng design
[email protected]
VÍ DỤ 2: EMBEDDED MACRO IN FORMS
[email protected]
[email protected]
VÍ DỤ 3
[email protected]
[email protected]
VÍ DỤ 4
[email protected]
[email protected]
THAY ĐỔI THUỘC TÍNH FORMBẰNG
MACRO
[email protected]
[email protected]
[email protected]
VÍ DỤ: TẠO MENU BAR CHO FORM
[email protected]
[email protected]
[email protected]
[email protected]