Author: Curtis Smith et al.
Translator: Chen Haibiao
Publisher: Tsinghua University Press
Publication Date: 1999-11-01
Features: Visual Basic is a useful tool for database development. This book introduces the upgraded version of Visual Basic 5.0, Visual Basic 6.0, in a step-by-step manner, aiming to enhance readers' ability to use Visual Basic for database programming. The book provides detailed explanations of Visual Basic 6.0-specific features such as the Microsoft Data Environment Designer and Report Designer, DAOJet data objects, ActiveX Data Objects, DED,, SQL-VB interpreter, error handling, database replication, and security. This book is suitable for beginners and intermediate database programmers, as well as advanced users and professionals.
Excerpt:
> In this chapter, we introduce all the constraint data controls included in the Professional Edition of Visual Basic, as well as special properties, events, and methods related to database programming. We will create a series of small programs to demonstrate how these constraint controls are used in database applications. Additionally, we will cover general rules for designing high-quality forms, including Windows program design, form layout, font selection, control placement, spacing, and color selection. Finally, we will build a small project that demonstrates how to create a custom color table within a program. This project illustrates how to use Windows "Control Panel" color controls to set the colors used in the program.
3.1 What Are Constraint Data Controls?
Before delving into the properties, events, and methods of Visual Basic constraint data controls, let's first understand what constraint controls are and why they are so useful.
New Term: Constraint Data Controls
Constraint data controls are similar to other Visual Basic control objects, but they have additional properties, events, and methods that allow them to be directly "bound" to one or more data tables. This binding makes it easier to create data-related input and display objects, enabling them to be used for data input and display with minimal code. Using constraint controls greatly simplifies programming. Most controls automatically handle some of the tedious tasks related to database input and display. Constraint controls simplify Visual Basic programming by handling all (or nearly all) of the following processes:
- Loading data from a database into Visual Basic data objects.
- Selecting the data records requested by the user.
- Loading the values of the requested records into form controls.
- Capturing simple user input errors.
- Enforcing database integrity rules.
- Updating data objects with values modified in form controls.
While it is not mandatory to use constraint controls, as some programs in the previous chapter used non-constraint controls, it is always better to leverage the advantages of data constraint controls when possible. Using pre-built and tested constraint controls allows you to create complete and practical database input forms in a short time.
3.2 Using Data Controls
Visual Basic data controls are used to access tables in a database. Data controls can be used to establish links with dynamic set data objects in a program or on a single form. Multiple data controls can be used in a program or on a single form. Like all other Visual Basic controls, data controls have their own properties, events, and methods. Since this book focuses on databases, this section emphasizes the properties, events, and methods that play a crucial role in database operations. In this section, we will create a small program to demonstrate the database-related features of Visual Basic data controls.
3.2.1 Data Control Properties
There are five notable properties of a data control:
- DatabaseName (database name)
- Exclusive (exclusive access)
- Options (options)
- ReadOnly (read-only)
- RecordSource (record source)
There is also a sixth property, Connect, which is used only for data access. Connect will be used when accessing non-Microsoft Access databases. More information about the Connect property can be found in Chapter 8.
3.2.1.1 Setting DatabaseName and RecordSource Properties
The DatabaseName and RecordSource properties were introduced in Chapter 2. The DatabaseName property contains the name of the database to be accessed. In Microsoft Access databases, it is the full drive name, path, and file name of the Microsoft Access database file. For example, to connect to the Microsoft Access database BOOKS6.MDB in the C:\DATA directory, the DatabaseName property must be set to C:\DATA\BOOKS6.MDB. This can be set in the Properties window at design time or using Visual Basic code at runtime. Below, we will create a project to demonstrate the properties, events, and methods of a data control.
Enter Visual Basic and create a new project. Place a data control on the form. In this project, use the default data control Name property, which is Data1. In Chapter 2, the DatabaseName and RecordSource properties were set using Visual Basic's Properties window at design time. Visual Basic also allows most control properties to be set at runtime. The advantage of setting properties at runtime is that the program can be compiled to let users decide which database and tables to access. In this example, we will set these properties using Visual Basic code at runtime.
New Term: Design time refers to the time when Visual Basic program design is being performed. Runtime refers to the time after design when the program is running.
Set the values of the data controls in a separate process called OpenDB. Double-click the form to open the Visual Basic code window, select Add Procedure from the Tools menu, and a dialog box will appear prompting you to enter the procedure name (Figure 3.1). Enter OpenDB. Ensure the Sub radio button is selected and click OK. Now, the start and end statements for the new procedure will appear, and you can begin entering the program code.
The following procedure sets the DatabaseName property of the data control in the current form. Note the path of the BOOKS6.MDB file entered. If the database file is installed elsewhere on your machine, you will need to change this path as well.
Visual Basic 6.0 Database Programming
📌 Related Posts
Literature
A Century of Chinese Sports Books
2026-09-26
Literature
The order of marketization in China's economy
2026-09-26
Literature
Semiconductor materials
2026-09-25
Literature
Zhang Ruimin made the decision for Haier's 66 classics.
2026-09-14
Literature
JavaScript in Practice and Improvement
2026-10-01
Literature
E-commerce Principles and Application Development Practice
2026-10-01
Literature
Microsoft Visual C++ 6.0 MFC Library Reference Class Library Reference (1)
2026-10-01
Literature
ARTISTS Painters (Realisms, Expressionisms, Abstractions)
2026-10-01