1. Trang chủ
  2. » Cao đẳng - Đại học

automatic tasks with visual basic

32 328 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Automatic Tasks with Visual Basic
Trường học Unknown University
Chuyên ngành Computer Science
Thể loại Lecture notes
Thành phố Unknown City
Định dạng
Số trang 32
Dung lượng 166,58 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

 When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.. Understanding VBA Terminology Some basic VBA terminology: − Statement: A word or

Trang 1

Automating Tasks with

Visual Basic

Trang 2

When can’t find a readymade macro action that does the job you want, you can use

Visual Basic code.

Example:

Modify a whole batch of records at once.

Perform complex calculations.

Interact with other programs on computer

Write even more complicated validation routines that lock out bad data.

Trang 3

Understanding VBA Terminology

Some basic VBA terminology:

Statement: A word or combination of words that constitutes an instruction to be

performed by the VBA engine.

Procedure: A collection of VBA statements that are grouped together to perform

a certain task There are two types of procedures:

Subroutines: perform a single task, no return.

Functions: perform a task and then return a value

Trang 4

Understanding VBA Terminology

Module: Procedures live in modules A module consists of one or more procedures

Variable: is nothing more than a name applied to represent a data value Variable

is used to hold values such as customer names, dates, and numeric values

manipulated by the VBA code.

Trang 5

The Visual Basic Editor

Visual Basic code is stored in database, but it need a different tool to view and edit it,

called the Visual Basic editor.

Open the Visual Basic editor:

In the Access ribbon, choose Database Tools Macro Visual Basic➝ ➝

Trang 6

The Visual Basic Editor

The Visual Basic editor window is divided into three main regions.

Project window: shows all the modules in your database

Properties window: which shows settings for the currently selected item in the Project window.

Document window: Edit code region.

Trang 7

Adding a New Module

In the Visual Basic editor’s menu, choose Insert Module

Trang 8

Adding a New Module

When add a new module, the Visual Basic editor automatically opens a code window

that shows the contents of that module.

Initially, a brand-new module has just one line of code:

Option Compare Database

This line is an instruction that tells Visual Basic how to handle operations that compare pieces of text.

Trang 9

Adding a New Module

Before write code you should add one more instruction to the top of code file:

Option Explicit

This instruction tells Visual Basic to use stricter error checking, which catches

common typos when using variables.

Trang 10

Simplest Possible Code Routine

Every module are one or more subroutines A subroutine is a named unit of code that

performs a distinct task

Subroutines start with the word Sub followed by the name of the subroutine and end

with the statement End Sub

Example:

Sub MyCodeRoutine()

MsgBox "Witness the power of my code."

End Sub

Trang 11

Module types

Access stores code in two places:

Class modules: attached to the form or report, it executes when the form or

report is opened, the class module does not appear in the modules section.

Standard modules: Code can also be stored in modules section Standard

modules is accessible to all objects in your database.

Trang 12

Responding to a Form Event

Open a form in Design mode.

Turn off Control wizard button.

Add a new button.

In the Property Sheet, choose the Event tab, and then select the button’s On Click

event

Click the ellipsis (…) in the On Click Event box

Select Code Builder and click OK

Ngày đăng: 04/05/2014, 18:15

w