MACRO 1 ttdung@utc 2.edu.vn
MACRO
NỘI DUNG
MACRO LÀ GÌ?1
PHÂN LOẠI MACRO2
STANDALONE MACRO3
DATA MACRO4
CONNECTING MACROS TO FORM5
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 khiCó 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
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 reportMacro 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
STANDALONE MACRO
TẠO STANDALONE MACRO
2. Chọn Action trong khung Add New Action hoặc Action catalog
MỘT SỐ ACTION THÔNGDỤNG
THIẾT LẬP ĐỐI SỐ CHOACTION
MỘT SỐ THAO TÁC KHI THIẾT KẾMACRO
Copy actionGiữ phím Ctrl, kéo Action đến vị trí mong muốn
Thêm commentAdd new action chọn Comment
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
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
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
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
NAME A KEY-ASSIGNMENTMACRO
^ indicate Ctrl key
+ indicate Shiftkey
Put {} around key names that are more than one letter long
OPENING DB THAT CONTAIN MACROS
CONDITIONAL EXECUTION (IF-THEN MACRO)
MSGBOX(MSG, TYPE, TITLE)
DATA MACRO
XÓA/ĐỔI TÊN DATAMACRO
CHỈNH SỬA MACRO
CHỈNH SỬA MACRO
VÍ DỤ 1
VÍ DỤ 2
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ếtBả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
TẠO NAMED MACRO
CONNECTING MACROS TO FORMS
EVENT
Control eventsXuất hiện khi thao tác với điều khiển
Ví dụ: On Click, On Change
Section eventsEvent xảy ra trên header hoặc footer của form
Ví dụ: On Mouse Move, On Click
Form eventsVí dụ: On Open, On Close, On Current, After Update
VÍ DỤ 1: STANDALONE MACRO IN FORMS
Tạo button bằng design
VÍ DỤ 2: EMBEDDED MACRO IN FORMS
VÍ DỤ 3
VÍ DỤ 4
THAY ĐỔI THUỘC TÍNH FORMBẰNG MACRO
VÍ DỤ: TẠO MENU BAR CHO FORM