0% found this document useful (0 votes)
15 views

Visual FoxPro Users Guide -- Microsoft -- ( WeLib.org )

The document is a User's Guide for Microsoft Visual FoxPro version 5.0, detailing its features as a relational database development system. It covers topics such as organizing information, creating tables, querying data, and integrating with other applications. The guide serves as a comprehensive resource for users to learn how to effectively utilize Visual FoxPro for data management and application development.

Uploaded by

Parpalabogdan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Visual FoxPro Users Guide -- Microsoft -- ( WeLib.org )

The document is a User's Guide for Microsoft Visual FoxPro version 5.0, detailing its features as a relational database development system. It covers topics such as organizing information, creating tables, querying data, and integrating with other applications. The guide serves as a comprehensive resource for users to learn how to effectively utilize Visual FoxPro for data management and application development.

Uploaded by

Parpalabogdan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 212

| Micresoft

Visual FoxPro.
User’s Guide |
Relational Database Development System for WindowSe
Digitized by the Internet Archive
in 2024

https ://archive.org/details/visualfoxprouserO000micr
User’s Guide

Microsoft: Visual FoxPro”

Version 5.0

Microsoft Corporation
Information in this document is subject to change without notice. Companies, names, and data used in examples herein are fictitious unless
otherwise noted. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without the express written permission of Microsoft Corporation.

© 1996 Microsoft Corporation. All rights reserved.

Microsoft, ActiveX, the Fox head design, FoxBase+, FoxPro, and Visual FoxPro are either registered trademarks or trademarks of Microsoft
Corporation in the USA and other countries.

dBASE and Paradox are registered trademarks of Borland International, Inc.


Lotus, and 1-2-3 are registered trademarks of Lotus Development Corporation.

Document No. FX91651-0896


Printed in the United States of America
Contents

Introduction xi
About This Book xi
Getting Help xiii
Need Help? Press Fl xiii
Sample Files xiii
Document Conversions xiil

Part 1 Organizing Information 1


Chapter 1 Getting Started 3
Starting Visual FoxPro 3
Introducing the Project Manager 5
Viewing What is in Your Project 6
Locating Data Files 6
Locating Form and Report Files 7
Viewing File Details 7
Adding and Removing Files 8
Creating and Modifying Files 9
Adding a Description to a File 9
Viewing Data in Tables 9
Sharing Files Between Projects 10
Customizing the Project Manager 10
Changing Your View 10
Introducing the Visual FoxPro Designers 12
Using Toolbars 12
Using Wizards 13
Starting a Wizard 13
Navigating the Wizard Screens 13
Saving Wizard Results 14
Modifying Wizard-Created Items 14
Using Builders 14

User’s Guide _ iii


Contents

Chapter 2 Creating Tables and Indexes 17


Creating a New Table 17
Choosing a Data Type 18
Using the Table Wizard 18
Starting the Table Designer 19
Storing and Viewing Information in Tables 20
Viewing the Contents of a Table 21
Moving Around ina Table 22
Editing Fields 22
Adding New Records to a Table 23
Deleting Records 23
Customizing a Browse Window 24
Rearranging Columns 24
Changing Column Widths 25
Turning Grid Lines On and Off 25
Splitting a Browse Window 25
Modifying Tables 26
Customizing Tables 28
Filtering a Table 28
Restricting Access to Fields 29
Ordering Data Using Indexes 30
Creating an Index 31
Choosing an Index Type 33
Ordering by Multiple Fields 33
Filtering Records 34
Using Indexes 34
Ordering Your Records 35
Controlling Entry of Duplicate Values in a Field 35

Chapter 3 Collecting Tables into a Database 37


Working with a Database 38
Creating a New Database 40
Adding Tables to a Database 41
Creating and Adding Views 41
Finding a Table or View in a Database 42
Relating Tables 42
Preparing for Relationships 42
Creating and Editing Relationships 44
Defining Field Display 45

iv User’s Guide
Contents

Setting a Field Caption 45


Entering Comments for a Field 46
Controlling Data Entry in a Field 46
Setting Default Field Values 47
Setting Validation Rules and Validation Text 47
Controlling Data Entry ina Record 49
Setting a Validation Rule fora Table 49
Setting a Trigger 50
Managing Records ina Database 50

Part 2 Finding Information 53


Chapter 4 Retrieving Data 55
Creating a Query 56
Using a Query Wizard 57
Starting the Query Designer 57
Defining Your Results 59
Selecting Fields You Want 59
Selecting All Fields for Output 59
Displaying an Alias for a Field 60
Setting the Order for Output Fields 60
Selecting the Records You Want 61
Organizing Your Results 62
Ordering Query Results 62
Grouping Query Results 63
Selecting the Groups You Want 64
Running Your Query 65
Directing the Results of Your Query 65
Verifying Your Query 67
Viewing Your SQL Statement 67
Adding a Comment to Your Query 67
Customizing Queries 68
Fine-Tuning Your Search 68
Narrowing Your Search 68
Expanding Your Search 69
Combining Conditions 70
Eliminating Duplicate Records from a Query 70
Retrieving a Number or Percentage of Top Records 70
Adding Expressions toa Query 71

User’s Guide v
Contents

Adding Expressions to Results 71


Filtering with Expressions 72

Chapter 5 Updating Data with Views 73


Creating Views 73
Using a View Wizard 74
Starting the View Designer 75
Connecting to Remote Data 76
Creating a Connection 77
Creating a New Remote View 78
Updating Data 79
Sending Updates to Tables 79
Making a Table Updatable 79
Setting Key Fields 80
Updating Specific Fields 80
Updating All Fields 81
Controlling How Update Conflicts are Detected 81
Customizing Views 82
Controlling Field Display and Data Entry 82
Controlling the Update Method 83
Adding Expressions to Remote Views 83
Prompting for Parameters 84
Setting Timeout Intervals 84
Optimizing Performance 85

Chapter 6 Querying and Updating Multiple Tables 87


Querying Multiple Tables and Views 87
Adding Views and Tables to a Query 88
Controlling Record Selection with Joins 89
Using Multiple Tables in Views 91
Using Multiple Remote Tables ina View 92
Combining Local and Remote Data ina View 93

Part 3 Displaying Information 95


Chapter 7 Designing Reports and Labels 97
Planning Your Report Layout 97
Determining the General Layout 98
Understanding Report Layout Files 99
Creating a Report Layout 100

vi User’s Guide
Contents

Using a Report Wizard 100


Starting the Report Designer 101
Creating a Mailing Label Layout 101
Using the Label Wizard 101
Starting the Label Designer 101
Modifying Your Layout 102
Planning Data Placement 103
Resizing Bands 105
Adding Report Controls 105
Adding Controls with Quick Report 105
Setting Report Data Sources 107
Adding Field Controls 109
Adding Label Controls 109
Adding a General Field 110
Selecting, Moving, and Resizing Report Controls 111
Copying and Deleting Report Controls 112
Aligning Controls 112
Adjusting Control Placement 113
Grouping Data on Your Layout 114
Adding a Single Group 115
Adding Multiple Data Groupings 115
Changing a Group Band 116
Deleting a Group Band 117
Changing the Grouping Order 117
Customizing Your Layout 118
Defining the Report Page 118
Setting the Margin, Paper Size, and Orientation 119
Defining the Page Header and Footer 120
Defining the Detail Band 120
Adding Title and Summary Bands 120
Formatting Field Controls 120
Defining Field Control Formats 120
Justifying Text ina Field 121
Changing Fonts 122
Adding Lines, Rectangles, and Circles 122
Drawing Lines 122
Drawing Rectangles 122
Drawing Rounded Rectangles and Circles 123
Changing Line Thickness or Style 123

User’s Guide vii


Contents

Adding a Picture 124


Changing Control Colors 125
Adding a Comment to a Control 125
Previewing and Printing Your Report or Label 125
Previewing Your Results 125
Printing Reports 126

CHAPTER 8 Managing Data Through Forms 129


Creating Forms 129
Using a Form Wizard 130
Starting the Form Designer 130
Adding Fields Quickly 131
Saving Forms 132
Running a Form 132
Adding Controls toa Form 133
Adding Controls to a Form with a Builder 133
Adding Fields to a Form with the Form Builder 134
Using Builders for All Controls 134
Adding Controls to a Wizard-Generated Form 134
Adding Controls and Setting Control Properties 135
Setting Up the Data Environment 135
Adding a Control toa Form 136
Adding Multiple Controls at One Time 137
Adding Controls Quickly 137
Setting Field Mapping Options 138
Quickly Creating a Single Control 139
Quickly Creating Multiple Controls 139
Modifying a Form 139
Using the Form Designer Toolbars 140
Selecting, Moving, and Resizing Controls 140
Copying and Deleting Form Controls 141
Aligning Controls 141
Adjusting Control Placement 142
Controlling the Grid Display 142
Setting Tab Order for Controls 142
Setting Tab Order Interactively 143
Setting Tab Order by List 143
Customizing Forms 143
Changing Text Fonts and Sizes 144

viii User’s Guide


Contents

Adding Shapes and Lines to Forms 144


Adding Graphics to a Form 145
Setting Form Colors 145
Setting the Maximum Form Design Area 146

Part 4 Using Visual FoxPro with Other


Applications 147
Chapter 9 Importing and Exporting Data 149
Understanding Importing and Exporting 149
Importing Data 151
Choosing a File Type to Import 151
Importing Data with the Import Wizard 152
Importing Data into a New Table 152
Importing from Lotus 1-2-3 153
Importing from Microsoft Excel 154
Appending Data 155
Choosing a File Type to Append 155
Appending Data with the Import Wizard 155
Appending Data to an Existing Table 156
Selecting Fields to Append 156
Selecting Records to Append 157
Appending Text Files 158
Appending Numeric or Currency Text 158
Exporting Data 158
Choosing a File Type to Export 159
Exporting Data to a New File 159
Selecting Fields to Export 160
Selecting Records To Export 161
Exporting Text Files 163
Exporting Numeric or Currency Values 163

Chapter 10 Sharing Information with Other Applications 165


Sharing Information Quickly 165
Copying and Pasting Data 165
Creating Mail Merges 166
Sending Mail from Visual FoxPro 167
Sharing Information Dynamically 167
Inserting Data in Tables 169

User’s Guide ix
Contents

Changing or Breaking Links to Data in Tables 170


Displaying Embedded or Linked Data on Forms 172
Changing or Breaking Links to Data on Forms 172
Displaying Embedded or Linked Data from Tables 173
Including Data in a Report 173
Editing OLE Objects in Forms and Tables 173
Replacing Linked or Embedded Data with Static Data 175
Index 177

x User’s Guide
Introduction

Welcome to Microsofts Visual FoxPro™, the relational database system that simplifies
data management and streamlines application development.
Visual FoxPro makes it easy for you to organize data, define database rules, and build
applications. You can quickly create forms, queries, and reports with the visual design
tools and wizards. Visual FoxPro also makes it possible for you to rapidly create full-
featured applications by providing an integrated development environment with
powerful object-oriented programming tools, client/server capabilities, and OLE and
ActiveX™ support.

About This Book


This book introduces you to Visual FoxPro as an interactive data management tool.
Read this book to become familiar with the basics of using Visual FoxPro, and learn
how to create tables, organize them into a database, and perform common database
management, querying and reporting tasks.

This book consists of four parts:


Part1 Organizing Information Includes a general orientation to Visual FoxPro,
information on how to work with and create tables, how to order them with indexes,
and how to organize them into a relational database system.
Part 2 Finding Information Discusses creating queries to extract the information
you need from your tables and databases, as well as creating views, a type of query
that enables you to update local and remote data.
Part3 Displaying Information Describes how to create reports and labels from
your tables, queries, and views, and how to create simple forms for displaying and
editing data.
Part 4 Using Visual FoxPro with Other Applications Describes how to bring
information from other applications into Visual FoxPro, how to save Visual FoxPro
data for use in other applications, and how to incorporate information or images from
other applications into Visual FoxPro tables, reports, and forms.

User’s Guide xi
Introduction

The User’s Guide is one element of an integrated set of conceptual, procedural, and
reference material, as the following illustration shows.

The Visual FoxPro Documentation Set

If you want to Use this information source


Install, configure, and optimize Visual FoxPro, installation Guide and Master Index
learn about new features, or use tiie master
index to look up information
Use Visual FoxPro interactively User’s Guide
Create applications with Visual FoxPro and Developer’s Guide
learn about programming techniques and how
to add advanced features to your application,
such as client/server capabilities, distributable
executables, Help files, and API libraries
Find full descriptions of Visual FoxPro Language Reference
commands, functions, properties, events,
and methods
Find reference information about Visual FoxPro Microsoft Visual FoxPro Help
online (FOXHELP.HLP)
Access all Visual FoxPro documentation inone Visual FoxPro Online Documentation on
place, supplemented with technical papers and CD (if supported for your country)
multimedia illustrations.
See the latest information on Visual FoxPro http://www.microsoft.com/vfoxpro

xii User’s Guide


Introduction

Getting Help
The Visual FoxPro Help system gives you quick access to information about using the
Visual FoxPro design tools and language elements.

Need He!p? Press F1


If you are working with a window or dialog box you do not understand, just press F1
to display a context-sensitive Help topic on that item.
You can get an overview of the contents of Help by choosing Microsoft Visual
FoxPro Help Topics from the Help menu. If you want to search for help on a specific
term or topic, choose the Index tab in Help.

Sample Files
A variety of sample applications, databases, and files are included with Visual FoxPro
to demonstrate programming techniques. For more information, choose Sample
Applications from the Help menu in Visual FoxPro.

Document Conventions
The following typographic conventions are used in this book.
Example Convention
setup Bold font indicates words, other than language commands,
that you must type.
Press the TAB key. Small capital letters denote the names of keys on the
Press SHIFT+F1. keyboard. A plus sign (+) indicates a combination of keys.
BUTTONS.VCX Capital letters indicate file names.
C:\WINDOWS Capital letters with separating backslashes are used for
paths.
event-driven Italic letters denote defined terms the first time they occur
in text.

User’s Guide xiii


_ « ere
I * ; ? : i

~~ : 7 :
| is
, inn Sh bh Tet: * a
-
boasts puss nt ek, Pe
7 wos ey idee te
7 windy " haere Astilesetae ete eRysie ag any”
= o¢cT~
a gita Jp RS see bs aordee wie ——
P. ie ~ Ae cae :a
:
/.
rq Rist ae
Pagin g pd bss iO aealiity ese,it
re sacar: nov =
Ae . eitiash gah LW ae atest sulesioa Ne inc ir(mea

ew
ftceil,gi HS puttmysMWit Bites Oy antite) woieoVvo. on tug
4 : 5 aw Boe
nica BEES,
=

a ange otto eae gladartnet-


: a AiO nicst aap
pTBnoauods Aero sat:

7 ape eo I
4 vated nied. ith ; a Shi voltae, eget api
ic = Minshe“gt eas prnel Pron
Y ie het
AD otter i ry

et
= ee eere, Misses re ‘init
mn re
ae ae is FAS
7 a>, tag a yn ;
a ; ‘
4 a ioe as 7

oe oy

PAW acne 7
oS Sa
PART 1

Organizing Information

We’re all deluged with information these days—the problem is


gathering it together and getting it organized so you can use it
effectively. This section discusses the cornerstones of a Visual
FoxPro data management system: tables, indexes, and databases.

Chapter 1 Getting Started


Here you’ll learn about your central interface for working with
Visual FoxPro—the Project Manager—and learn about the design
tools and wizards that make it easy to get quick results.

Chapter 2 Creating Tables and Indexes


Whether you import information from other applications, convert it
from existing database files, or retrieve it from a remote server, you
can use information more effectively when it’s in tabular form and
indexed. Indexes help you put your data into a meaningful order,
speed up searches for records, and join tables that contain related
information.

Chapter 3 Collecting Tables into a Database


Your tables can work together most effectively if you combine them
into a database. Databases give you more power to control and
validate the information entered into your tables.

User's Guide 1
7 TARAS

fortsmotal onixiag

“Linuldtne, sit sich o50) aoneenm’gg dig Suguta


b {le as
i Sey Lut wen? oe bey Lagprarnes hn gutiioy
5Tia 22 Page: a grist ep
vscedd¥. Vey BARN IA Mg PORALIMYeiiyps wil Tis sie
| eeeh itch Brus. Zoran
oad
. abel) jeadate aiden
—— ginh antait
1

ie . verats sited i wigan. -


Me gqulseveten sangint |WETS mute
hinds aogah B yoy ni
_ eh aly 1iQoy mizok bina seyenal — ati wod lage
a, mseise ali} Meta Yate fratniy
yy i ah) phat ey~ ned i

Mriatiapaalee. galt Sight


sa ang tee iiolestinges rai Most wikranrvectthy?igaxejetns
wor x:
nay. SRI? SOT OT IS tn Y N osietinay oneeaae
bites te or Sauatee® ai: aes “ato Pipa texs
De glared wwe
ad aay ee
tae Aghartitinea ¢ Hidi tied vinoy wy VON
Ststeoxdhal barehat —
‘Bali enedne IMR ah one xliycads it ang ia tybrome
a
Gpetaietls sbcaas gnitostiod fwwige a
ye ae wea Hh deiyie d
bah eae sridlieget tow ts opldiat wy
i

(chai totes ob ewer ajuty NON Sy eacmelateCl condita » atal


eal terninany tye) ania nailwepacied
ontabiley

b abinsd eraaty
CHAPTER 1

Getting Started

Welcome to Visual FoxPro, the powerful object-oriented environment for database


construction and application development. Visual FoxPro provides all the tools you
need to manage data, whether you are organizing tables of information and running
queries, creating an integrated relational database system, or programming a fully-
developed data management application for end users.

This chapter discusses:


¢ Starting Visual FoxPro
¢ Introducing the Project Manager
¢ Introducing the Visual FoxPro Designers
¢ Using Toolbars
¢ Using Wizards
¢ Using Builders

Starting Visual FoxPro


If Visual FoxPro is not currently on your computer, you need to complete the Setup
procedure. Setup instructions are in Chapter 1, “Installing Visual FoxPro,” in the
Installation Guide and Master Index.

> To start Visual FoxPro


¢ Double-click the Microsoft Visual FoxPro icon.

When you first start Visual FoxPro, the Project Manager creates a new, empty project
so you can add existing items to your project or create new items to include in the
project.
Using the Project Manager, you can quickly familiarize yourself with Visual FoxPro.
The Project Manager provides an easy, visual way to organize and work with tables,
forms, databases, reports, queries, and other files when you are managing tables and
databases or creating an application.

User’s Guide 3
Part 1 Organizing Information

The Project Manager organizes your data.

Project Manager

Manager - Projl : os pmo

Dee | 5
Ep Data
ae]
EE] Free Tables
. EE Queries
Ac: Documents
&}-E) Forms
» 4 Reports
€ Labels

Class
Libraries Views

Code

If you have your own set of tables from earlier versions of FoxProe, you can add them
to a project immediately to see how Visual FoxPro works. If you have other data you
want to organize (be it in spreadsheets, text files, or tables from other applications),
you can import it into Visual FoxPro and add it to a project. For more information, see
Chapter 9, “Importing and Exporting Data.”

You can also create a new project at any time by choosing the New option from the
File menu.

> To create a new project


1 From the File menu, choose New.
2 Select Project and choose New File.
3 In the Create dialog box, type the name you want to assign to the new project.
4 Choose Create.

To help you become familiar with Visual FoxPro, you can also use the sample files
that are provided. These samples are located in the SAMPLES subdirectory where
you installed Visual FoxPro.

TESTDATA.DBC
This database contains a simple set of related tables that you can experiment with
while becoming familiar with Visual FoxPro. This database was used to create the
examples in this book.

4 User’s Guide
Chapter 1 Getting Started

TASTRADE.PJX
This project contains a fully-developed end-user application that you can use to
understand the type of application you can develop with Visual FoxPro. By opening
the project and examining how it is structured, you can gain insight into how to
assemble an application. For more information about developing an application, see
the Developer’s Guide.

Introducing the Project Manager


The Project Manager is the primary organizational tool for working with data and
objects in Visual FoxPro. A project is a collection of files, data, documents, and
Visual FoxPro objects that is saved as a file with a .PJX extension.

The Project Manager is your “control center” for working with Visual FoxPro.

Choose a tab to see different


categories in your project...

Dat r
Documents
&. Class Libraries
4 Code
Other
...then choose one of the
command buttons.

You can use the Project Manager to organize and manage files as you create tables
and databases, write queries, set up forms and reports, and build applications. For
more information about building applications with the Project Manager, see the
Developer’s Guide.
You can begin creating your own project by adding existing Visual FoxPro .DBF files
to a new project, or by using the sample files found in the \SAMPLES\DATA
directory where you installed Visual FoxPro.

User’s Guide 5
Part 1 Organizing Information

Viewing What is in Your Project


The Project Manager presents an organized, hierarchical view of your data. To focus
on a particular type of file or object in your project, choose the appropriate tab.
When you are setting up tables and databases and creating forms, queries, views, and
reports, you work primarily with the items shown under the Data and Documents tabs.

Locating Data Files


This tab contains all the data for a project: the databases, free tables, queries, and
views.

The Data tab in the Project Manager

Click here to see the


data stored in a project.
Eh Databases
a ofl
i Tables
FY Local Views
@ Remote Views
® Connections
cof} Stored Procedures
Free T ables
Queries

Databases are sets of tables, usually related to each other through common fields. To
support the tables and relationships, you can also include views, connections, stored
procedures, business rules, and triggers in your database. You create a database with
the Database Designer, which is introduced in Chapter 3, “Collecting Tables into a
Database.” Database files have a .DBC extension.
Free tables are tables which are not part of a database and are stored in a file with a
.DBF extension. Creating tables is discussed in Chapter 2, “Creating Tables and
Indexes.”
Queries are a structured way to request specific information stored in tables. Using the
Query Designer, you format a question that extracts records from your tables based on
the criteria you enter. Queries are SQL-Select commands saved as text files with a
-QPR extension. For more information about queries, see Chapter 4, “Retrieving
Data.”

Views are specialized queries that enable you to access both local and remote data and
allows for update of data sources by making changes to the records returned by the
query. Views exist only within a database and are not independent files. For more
information about views, see Chapter 5, “Updating Data with Views.”

6 User’s Guide
Chapter 1 Getting Started

Locating Form and Report Files


The Documents tab contains all the documents you use when working with data:
forms for entering and viewing data, and reports and labels for printing tables and
query results.

The Documents tab in the Project Manager

Click here to see the


document stored in a project.
1 Boni
Reports
€ Labels

Forms are used to display and edit the contents of tables. Creating forms with the
Form Designer is discussed in Chapter 8, “Managing Data Through Forms.”
Reports are files that tell Visual FoxPro how to format and print the results of queries
run on tables. Creating reports with the Report Designer is discussed in Chapter 7,
“Designing Reports and Labels.” Labels are special reports formatted to print on label
stock.
The other tabs—Classes, Code, and Other—are primarily used when creating
applications for end users. Working with classes, code, and other files is discussed in
the Developer’s Guide in the context of creating an application.

Viewing File Details


The items in the Project Manager are organized in an outline view that you can
expand or collapse to look at different levels of detail.
A plus sign (+) appears next to a symbol if there are one or more items of that type in
the project. Click the plus sign next to a symbol to display the names of items of that
type in the project. Click the plus sign next to the name of an item to see the
components of that item.
For example, click the plus sign next to the Free Tables symbol to see the names of
free tables in the project; click the plus sign next to a table name to see the names of
the fields and indexes within that table.

User’s Guide 7
Part 1 Organizing Information

The outline view shows different levels of detail in your project.

Click the plus sign


to expand an item.
; ; : -EE] @ customer
Click the minus sign : @ employee
to collapse a list.
lis GEAie
@ orders

To collapse a list once it is expanded, click the minus sign that appears next to the list.

Adding and Removing Files


To use the Project Manager, you must add existing files to it or use it to create new
files. For example, if you have a set of existing .DBF tables you want to add to a
project, just select Free Tables in the Data tab and use the Add button to add them to
the project.

> To add a file to a project


1 Select the type of item you want to add.
2 Choose Add.
3 In the Open dialog box, select the name of the file you want to add and choose
OK.

> To remove a file from a project


1 Select the element you want to remove.
2 Choose Remove.
3 In the confirmation prompt, choose Remove.

If you want to delete the file from your computer, choose Delete.

8 User’s Guide
Chapter 1 Getting Started

Creating and Modifying Files


The Project Manager simplifies creating and modifying files. Just select the type of
file you want to create or modify and choose the New or Modify button. Visual
FoxPro displays the design tool appropriate to the type of file you selected.

> To create a file to add to the Project Manager


1 Select the element you want to create.
2 Choose New.

With some items, you have the option to use a wizard to help you create the file.

> To modify a file


1 Select an existing file.
2 Choose Modify.

For example, to modify a table, select the name of the table and choose Modify to
display the table in the Table Designer.

Adding a Description to a File


When you create or add a new file, you can add a description to the file. This
description is shown at the bottom of the Project Manager when the file is selected.

> To add a description to a file


1 Inthe Project Manager, select the file.
2 From the Project menu, choose Edit Description.
3 In the Description dialog box, type a description for the file.
4 Choose OK.

Viewing Data in Tables


From the Project Manager, you can browse the contents of the tables in your project.

> To browse a table


1 Select the Data tab.

2 Select a table and choose Browse.

Viewing tables in a Browse window is discussed in Chapter 2, “Creating Tables and


Indexes.”

User’s Guide 9
Part 1 Organizing Information

Sharing Files Between Projects


You can reuse your work from one project by sharing files with another project. The
files are not duplicated, because the project stores only a reference to the file. Files
can be associated with different projects simultaneously.

> To share files between projects


1 In Visual FoxPro, open the two projects that will share the file.
2 Inthe Project Manager containing the file, select the file.
3 Drag the file to the container for the other project.

Customizing the Project Manager


You can customize your visual work area by changing your view of the Project
Manager or by setting double-click to run files in the Project Manager. For more
information about customizing your visual work area, see Chapter 3, “Configuring
Visual FoxPro”, in the Installation Guide and Master Index.

Changing Your View


Initially, the Project Manager appears as a separate window. You can move the
container, resize it, or collapse it so that only the tabs show.

> To move the Project Manager


¢ Place the pointer in the title bar and drag to a new location on your screen.

> To resize the Project Manager


¢ Place the pointer on the top, bottom, side, or corner of the Project Manager
window, and drag to increase or decrease size.

> To collapse the Project Manager


¢ Click the up arrow in the upper-right corner.

Only the tabs show in collapsed view

You can easily return the Project Manager to its usual size.

> To restore the Project Manager


* Click the down arrow in the upper-right corner.

10 User’s Guide
Chapter 1 Getting Started

When the container is collapsed, you can tear off and arrange individual tabs to suit
your workspace preferences. When you tear off a tab, it floats independently in the
main Visual FoxPro window.

> To tear off a tab


1 Collapse the container.
2 Select a tab and drag it away from the Project Manager.

When a tab is floating, you can access the options on the Project menu by right-
clicking the mouse in the floating tab.
If you want the tab to always remain on top, click the pushpin icon at the top of the
tab. The tab will remain on top of other Visual FoxPro windows. You can set more
than one tab to be “always on top.” To remove the “always on top” setting on a tab,
click the pushpin icon again.

Project Manager tabs

Click here to keep a tab on


top of other windows. eae
z"9 Click here to
collapse a tab.
Reports
€? Labels
e @ customer
e @ employee
200
& @ orders
Queries

Drag to remove tabs from the


collapsed Project Manager.

> To restore a tab


* Click the Close button on the tab.
2Ore-
¢ Drag the tab back into the Project Manager.

You can also attach or dock the Project Manager so that it appears as a toolbar on the
top of your main Visual FoxPro window.

> To dock the Project Manager


* Drag the Project Manager to the top of the main Visual FoxPro window.

User’s Guide 11
Part 1 Organizing Information

When the Project Manager is docked, it becomes part of the toolbar area of the
window. You can’t expand the Project Manager window when it’s docked; instead,
you Click on individual tabs to use them. You can also tear off tabs from a docked
Project Manager.

Introducing the Visual FoxPro Designers


The Project Manager gives you quick access to the Visual FoxPro designers. These
tools make it easy to create tables, forms, databases, queries, and reports to manage
your data.
This book describes how to use the designers. You can also assemble the items you
create with the designers into an application. Creating an application from tables,
databases, and forms is discussed in the Developer’s Guide.
You can also use the designers independently from the Project Manager by using the
options of the New command on the File menu. The following table summarizes
which designers to use to accomplish different tasks.
To Use this designer
Create tables and set indexes on tables Table Designer
Run queries on local tables Query Designer
Run queries on remote data sources; create updatable queries View Designer
Create a form for viewing and editing the data in your tables Form Designer
Create a report for displaying and printing your data Report Designer
Set up a database; view and create relationships between tables Database Designer
Create a connection for remote views Connection Designer

> To use the designers to create new files


¢ Inthe Project Manager, select the type of file you want to create and choose New.

Using Toolbars
Each designer has one or more toolbars that give you quick access to the most
commonly used features or actions of the tool. For example, the Form Designer has
separate toolbars for controls and control layout, and a color palette.
You can place as many toolbars on your screen as you need while working. You can
dock toolbars to the top, bottom, or sides of your screen to customize your working
environment. Visual FoxPro saves the positions of the toolbars so they remain where
you last placed them.

> To display toolbars


1 From the View menu, choose Toolbars.

12 User’s Guide
Chapter 1 Getting Started

2 Inthe Toolbars dialog box, select the toolbars you want to use.
3 Choose OK.

> To dock a toolbar


¢ Drag the toolbar to the top, bottom, or side of your screen.

Using Wizards
Wizards are interactive programs that help you quickly accomplish common tasks
such as creating forms, formatting reports, and setting up queries.
By answering questions or choosing options on the series of wizard screens, you are
telling the wizard to build a file or perform a task based on your responses. For
example, if you choose the Report Wizard, you can select the type of report you want
to create. The wizard then asks which table you want to use and provides choices for
formatting the report.

Starting a Wizard
When you create a new item using the Project Manager or the File menu, you can
choose to use a wizard to help you create the item.

> To start a Wizard


1 In the Project Manager, select the type of file you want to create, and choose
New.
You can also choose New from the File menu and select the type of file you want
to create.
2 Select the Wizard option.

You can also access most wizards directly by choosing the Wizards command from
the Tools menu.

Navigating the Wizard Screens


Once you have the wizard running, just answer the questions on each screen. When
you are ready to proceed to the next screen, choose the Next button.
If you make a mistake or change your mind, choose the Back button to see the
previous screen so you can make changes. Choose Cancel to exit the wizard without
producing any results. If you have a question about using the wizard, press F1 to get
Help.

User’s Guide 13
Part 1 Organizing Information

When you reach the last screen, choose the Finish button to exit the wizard.
If you are in a hurry, you can choose the Finish button to proceed to the end of the
wizard sequence, skipping the entry of optional information and using defaults
supplied by the wizard.

Saving Wizard Results


The last screen of each wizard might ask you to supply a title and, depending upon the
type of wizard you are using, give you options to save, browse, modify, or print your
results.
Use the Preview option to see the results of the wizard before you are finished with
the wizard. You can rerun the wizard if you want to make different choices to change
the results. When you are satisfied with the wizard results, choose the Finish button.

Modifying Wizard-Created Items


Once you have created a table, form, query, or report, you can open it in the
appropriate design tool and make further changes to it. You cannot reopen a wizard-
generated file with a wizard, but you can preview the wizard results and make
changes before exiting the wizard.

Using Builders
Builders are tabbed dialog boxes that simplify creating and modifying forms, complex
controls, and referential integrity code. Each builder displays a series of tabs so you
can set the properties of the selected object. You can use builders for some controls,
for forms, for formatting controls, and for creating referential integrity between
database tables.

> To build a control


¢ From the Form Controls toolbar, choose the Builder Lock button. Each time you
add a new control to a form, Visual FoxPro displays the appropriate builder.
Or
* Select a control on the form and choose the Builder button in the Properties
window.

> To use the Form Builder


¢ From the Form menu, choose Quick Form.

Once you have several controls on a form, you can format them all at the same time
with the AutoFormat Builder.

14 User’s Guide
Chapter 1 Getting Started

> To format several controls


1 In the Form Designer, select controls.
2 From the Form Designer Toolbar, choose the AutoFormat button.

When a builder is displayed, select the options for each tab and then choose OK to
register the changes.
To See
Build a combo box Combo Box Builder
Build a command group Command Group Builder
Build an edit box Edit Box Builder
Build a form Form Builder
Build a grid Grid Builder
Build a list box List Box Builder
Build an option group Option Group Builder
Build a text box Text Box Builder
Format a group of controls AutoFormat Builder
Create referential integrity between database tables Referential Integrity Builder

User’s Guide 15
a te WE. eis. aed Pea. ise 3
‘ ™~ nett ar
=a
:
oy
“a omy 6 yore bee Seen anise wine mh 4 eer

ane a
ger AS ht eo
taht UD nO HC
bosheare)
oe -
mealies
item Sonia hienee re
apie S

ae ta - ae ahcers “Gai ies Meek PoRads alate webrive

. FM ep Se oe are Rave at Phe Es. tae nds bia’


: ew, hci or, 2 gD a hee ens Ate blag ebtind SS
Ree
i
- . eo is cs 1) :
| etNee os
ks +S ee nee biive
a : a.

Mae ay OP YS Shatin gy eimget fers | — oo


ee* ;
| @ ae ss Psi
——
rom ee any mS FE a ep ‘weet ane Shes
F Teor ¢ ae 5 oD ha pa pg é ‘as see , “egtht : 4 .~

ee ai Seca Raa selene a Jakimenebow aber SS


eae Es
ad : _ a eH ‘ <

iran eiiciers eh tea


“>; >a «é © = a , h >,
= — A ;
- - Givi oi af Pai) “ee : a 7 = ‘—
>
a f a a
eh 2 ee cae er >, >
in
i Ot) i ee
: ‘ ee wral, see altstagMaha, ames : oeee
.? _ pt th j aie
; © Sy Fe hess Wai ry etee rt
ave ' Ort
g pe 1 el
PIR: ee ae
« _ ARTS
as eis a
Kael
ny
Ole 1 ie Tiley The° whbs gona
a Pp ee oS tes +e cet seein Bye:i tindeaall Cee

7 s DON gts 50 sai, h . ae in

e- & WAide:
ea tcorilen 3FN et eee telected wens §esheets
4 le ——.
a
lanes ane & pass Ree seen ee es
_ ‘.

VED ep teen otal em it mga -

adWanciaigitma)
. han - tes te bin ih Hae
in al ste ute ithhon Been, gna
aCe”. “ Seca paar
CHAP
1 ER 2

Creating Tables and Indexes

Tables are the basic units you use for working with data and creating relational
databases and applications. You might need to work with information currently stored
in tables, customize existing tables, or create your own custom tables to store data. To
order your data and speed up processing, you can use indexes.
This chapter shows how to work with and modify existing tables, and how to create
new tables with Visual FoxPro, either with assistance from the Table Wizard, or using
the Table Designer directly. For information about importing table information from
other applications, see Chapter 9, “Importing and Exporting Data.” For information
about the additional properties of tables available when they are incorporated into a
database, see Chapter 3, “Collecting Tables into a Database.” For more information
about indexes, see Chapter 7, “Working with Tables,” in the Developer’s Guide.

This chapter discusses:


* Creating a New Table
¢ Storing and Viewing Information in Tables
¢ Modifying Tables
¢ Customizing Tables
¢ Ordering Data Using Indexes
* Creating an Index
* Using Indexes

Creating a New Table


When you need to create a new table, you can get assistance from the Table Wizard,
or use the Table Designer and set up a table with the fields you need.

User’s Guide 17
Part 1 Organizing Information

Remember these main points when you set up a table:

¢ Make the data type for a field match the kind of information you are going to store
in it. For more information, see the following section, “Choosing a Data Type.”
° Make the field wide enough to accommodate the information it will display.
* Set an appropriate number of decimal places for Numeric or Float fields.
¢ Check NULL if you want the field to accept .NULL. as a value.

Choosing a Data Type


Each field in your table holds a particular type of data. You can set the data type of a
field to any of the types in the following table.
Data Type Description Example

Character Alphanumeric text A customer’s address


Currency Monetary units Purchase price
Numeric Integer or decimal numbers Quantity of items ordered
Float Same as Numeric
Date Month, day, and year Date an order was placed
DateTime Month, day, year, hours, minutes, and Date and time an employee
seconds arrived at work
Double Double-precision number Data from experiments that
require a high degree of precision
Integer Non-decimal numeric values (whole Line number in an order
numbers)
Logical True or False Whether or not an order has been
filled
Memo Alphanumeric text of an indeterminate Notes about phone calls in a
length phone log
General OLE Microsoft Excel worksheet
Character (Binary) Same as Character but values aren’t User passwords stored in a table
translated when the code page changes and used in different countries
Memo (Binary) Same as Memo but values aren’t A logon script used in different
translated when the code page changes countries

Using the Table Wizard


Whenever you want to create a new table, you can use the Table Wizard to help you
set it up. The wizard will ask you a series of questions and build a table for you based
on your answers.

18 User's Guide
Chapter 2 Creating Tables and Indexes

> To create a table with a wizard


1 In the Project Manager, select the Data tab and select Free Tables.
2 Choose New.
3 Choose the Table Wizard button.
4 Follow the instructions on the wizard screens.

You can also access the Table Wizard from the menu by choosing New from the File
menu, selecting Table, and selecting the Table Wizard option.

Starting the Table Designer


If you want to create your own table without using a wizard, use Tables in the Project
Manager Data tab or choose New from the File menu, select Table, and choose New
File.

Starting a new table in the Table Designer

Start by typing the name of the first field here.

If you want to create a table to add to a database, open a database before creating a
new table, and the new table will automatically become part of the database. You can
also add it later. For more information about database tables, see Chapter 3,
“Collecting Tables into a Database.”

> To create a new table


1 In the Project Manager, choose Tables under Databases, or choose Free Tables.

2 Choose New, and then choose New Table.


3 Inthe Create dialog box, enter a name for the table and choose Save.
4 On the Fields tab of the Table Designer, type the name for the first field in the
Name field.
5 Inthe Type field, select a field type from the list.

User’s Guide 19
Part 1 Organizing Information

In the Width column, set the width of the column in characters.


If Type is Numeric or Float, set the number of decimal places to display in the
Decimal box.
8 If you want to add an index to the field, select a sort order in the Index column.
9 If you want the field to accept the input of null values, select NULL.
You can choose to begin entering records immediately, or open the table later when
ready to enter records.

> To add records to a table


1 In the Project Manager, select the name of the table.
2 Choose Browse.
3 From the View menu, choose Append Mode.
4 Enter new record changes in the Browse window.
If you prefer to view each field on a separate line, switch to Edit mode by choosing
Edit from the View menu.

Storing and Viewing Information in Tables


Tables store your data in a row and column format, similar to a spreadsheet. Each row
represents a record, and each column represents the fields in the records.

Rows and columns in tables

t /customer_id Character
company_name Character
contact_name Character 30
/] contact_title Character 40
4 address Character 60
: city Character

paredados y helados :Ana Trujillo

Each row represents a


record in the table. lauer See Delikatessen Hanna Moos

20 User’s Guide
Chapter 2 Creating Tables and Indexes

You can create two types of tables in Visual FoxPro: database tables, which have been
incorporated as part of a database, and free tables, which are independent of any
database.

Viewing the Contents of a Table


The quickest way to see the contents of a table is to look at it ina Browse window.
The Browse window displays the contents of the table as a series of rows and columns
you can scroll through. To familiarize yourself with some typical tables, you can
browse the sample tables in the SAMPLES\DATA subdirectory where you installed
Visual FoxPro.

> To browse a table


1 From the File menu, choose Open and select the name of the table you want to
view.
2 From the View menu, choose Browse.

You can also select the name of a table in the Project Manager, and choose the Browse
button.
For example, open the Customer table in SAMPLES\DATA.

Table in a Browse window

Matia Anders Each column is a database field.

Each row is a
database record.

Use the scroll bars to


move through the table.

For easier data entry, you can place a Browse window into Edit mode. In Edit mode,
the column names are displayed on the left side of the window.

User’s Guide 21
Part 1 Organizing Information

> To change the Browse window to Edit mode


¢ From the View menu, choose Edit.

Table in Edit mode

gg Customer_a
Customer_id
“| [(Company_nameAllreds Futterkiste
_| |Contact_name Maria Anders
: Contact_title Sales Representative
ddress Obere Str. 57
| ICity Berlin
| [Region
) |Postal_code 12203
Country Germany
_| [Phone 030-0074321
| [Fax O30-0076545
_| |Max_order_amt 6300.0000
1 |Min_order_amt 2600.0000
| [Discount 2

Customer_id ANATR
- | [Company_namedna Trujillo Emparedados y helados

In either mode, you can scroll through records, search for specific records, and make
changes directly to the contents of the table.

Moving Around in a Table


Use the scroll bars to move through the table and display different fields and records.
You can also use the arrow keys and the TAB key to move around.

> To see different records


1 From the Table menu, choose Go to Record.
2 Inthe submenu, choose Top, Bottom, Next, Previous, or Record #.
3 If you choose Record #, enter the record number you want to see in the Go to
Record dialog box, and choose Go To.

Editing Fields
To change the current information in a Character, Numeric, Logical, Date, or
DateTime field, either place the cursor in the field and edit the information, or select
the entire field and begin typing the new information.
To edit the information in a Memo field, double-click the field in the Browse window
or press CTRL+PGDN. An editing window opens with the contents of the memo field.
A General field contains an embedded or linked OLE object. You can edit this object
by double-clicking the General field in the Browse window and either editing the
document directly (as with a Microsoft Word document or a Microsoft Excel
worksheet) or double-clicking on the object to open the parent application (as with a
Microsoft Paint object).

22 User’s Guide
Chapter 2 Creating Tables and Indexes

Adding New Records to a Table


To quickly add new records to a table, you can place the Browse or Edit windows into
Append mode. In Append mode, a blank set of fields appears at the bottom of the file,
so you can fill them in to create a new record.

> To add a new blank record


¢ From the View menu, select Append Mode.

Fill in the fields in the new record, tabbing from field to field. A new record is created
at the bottom of the file as you complete each record.

Append Mode for a Browse window


ma Customer_a

Enter a new record at the bottom


of the Browse window.

Deleting Records
Deleting records from a table is a two-step process in Visual FoxPro. First, you mark
the records for deletion by clicking the box to the left of each record.

Records marked for deletion

gy Customer

Click in this column


next to records you
Antonio Moreno Taqueria ntonio Moreno
want deleted.

Blauer See Delikatessen

comercial Moctezumna

User’s Guide 23
Part 1 Organizing Information

Marking the records does not delete them. To actually remove the records, you choose
Remove Deleted Records from the Table menu. This process deletes the records you
marked, and consolidates the remaining records in the table. Removing the deleted
records closes the table, so you must re-open it to continue working.

> To delete records from a table


1 Mark the records you want to delete by clicking in the left column.
2 From the Table menu, choose Remove Deleted Records.
3 Choose Yes in response to the prompt that asks if you want to pack the table.

You can also select a group of records for deletion by setting conditions in the Delete
dialog box. Choose Delete Records from the Table menu to enter deletion criteria.

Delete dialog box

Customer. country = “UK?


Zi

Choose the Scope button to set the range of records to be deleted.


If you can describe a set of records you want to delete, you can build an expression
based on that description. Choose the FOR button to bring up the Expression Builder
so you can build an expression. For example, using the expression FOR Country =
'UK' selects all the records from the UK and marks them for deletion.

Customizing a Browse Window


To customize the Browse window to fit your needs, you can rearrange or change the
width of columns, turn the grid lines on or off, and split the Browse window into two
panes.

Rearranging Columns
You can rearrange the columns of the Browse window into the order you want. This
does not affect the actual structure of the table.

> To rearrange the columns in a Browse window


¢ Drag a column heading to a new location.
Ors

¢ From the Table menu, choose Move Field, and use the LEFT ARROW or RIGHT
ARROW keys to move the column. Press ENTER when you are done.

24 User’s Guide
Chapter 2 Creating Tables and Indexes

Changing Column Widths


You can also change the width of a column in a Browse window. This resizing does
not affect the field length or the structure of the table.
If you want to change the actual length of the fields, modify the structure of the table
using the Table Designer (see “Modifying Tables” later in this chapter).

> To change the width of a column


* Position the pointer in the column heading between two field names, and drag the
pointer to resize the column.
Ore
¢ Select a field, and from the Table menu, choose Size Field, and use the LEFT
ARROW Or RIGHT ARROW keys to resize the column. Press ENTER when done.

Turning Grid Lines On and Off


You can also turn off the grid lines in a Browse window.

> To turn grid lines on or off


¢ From the View menu, choose Gridlines.

Splitting a Browse Window


You may find it useful to split the Browse window so that you can look at two
different areas in the table, or look at the same records in Browse and Edit modes
simultaneously.

Split Browse window

Ay. dos Lusiadas, 23


Sao Paulo
Se
Brazil
(11) 555-7647

Discount 10
Customer ID
(Contact_name Pedro Afonso
Contact_title Sales Associate
Postal_code 05432-043
Max_order_amt5400.0000
Hin_order_amt 0.0000
Sales_region
Comercio Mineo

Browse mode i Edit mode

User’s Guide 25
Part 1 Organizing Information

> To split a Browse window


1 Place the pointer on the split bar at the bottom left corner of the view.
2 Drag the split bar to the right to divide the Browse window into two panes.
_Or-
From the Table menu, choose Resize Partitions.
Press the RIGHT ARROW key to move the split bar.
Press ENTER.

To resize the panes of a split Browse window


Place the pointer on the split bar.
Drag the split bar to the right or left to change the relative size of the panes.
fed
From the Table menu, choose Resize Partitions.
2 Press the LEFT ARROW or RIGHT ARROW key to move the split bar.
3 Press ENTER.

By default, the two panes of the browse window are linked; that is, as you select
different records in one pane, the change is reflected im the other. If you want to
detach the two panes so that they function independently, (that is, so that scrolling one
pane does not affect the other) clear the Link Partitions command on the Table menu.

Modifying Tables
When you need to make changes to the structure of an existing table, use the Table
Designer. With the Table Designer, you can add and delete fields, set data types and
widths for fields, and view and set the indexes which sort the contents of the table.

If the table you are modifying is part of a database, additional database-specific field
and table properties are available. Use of these properties is covered in Chapter 3,
“Collecting Tables into a Database.”

26 User’s Guide
Chapter 2 Creating Tables and Indexes

> To modify a table


¢ In the Project Manager, select the name of a table and choose Modify.

The structure of the table is displayed in the Table Designer.

Table Designer shows current table structure


- customer. dbf
\

company_name Character
{ contact_name Character
Character
Character
Character

‘Customer ID

Customer ID

> To add a field to a table


1 Inthe Table Designer, choose Insert.
2 In the Name column, type the name of the new field.
3 Inthe Type column, select a data type for the field.
4 Inthe Width column, set or enter a width for the field.
5 If the field has a type of Numeric or Float, set the number of decimal places in the
Decimal column.
If you want the table to accept null values, select the NULL column.
Choose OK.
Choose Yes to make the table structure changes.

> To delete a field from a table


¢ Select the field and choose Delete.

User’s Guide 27
Part 1 Organizing Information

Customizing Tables
You can customize your tables so that only certain records are displayed by setting a
filter on the table. You can also restrict access to certain fields in a table by setting a
field filter, which allows you to select which fields to display.

Filtering a Table
If you want to see only records of a certain type, you can set a filter to limit the
records shown in the Browse window. Filtering is useful when, for example, you want
to restrict the browse to show only sales above a certain amount, or employees in a
range of hire dates.
To set a filter, use the Work Area Properties dialog box, available through the
Properties command on the Table menu.

Work Area Properties dialog box


Work Area Properties
yy i

Filter expression limits records shown in table.

> To seta filter on a table


1 Browse the table you want to filter.
2 From the Table menu, choose Properties.
3 In the Work Area Properties dialog box, enter your filter expression directly in
the Data filter box.
=O)

¢ Choose the dialog button under Data Filter, and in the Expression Builder, create
an expression to select the records you want to see and choose OK.

When you browse the table, you see only records that are selected by the filter
expression.

28 User’s Guide
Chapter 2 Creating Tables and Indexes

For example, using the Customers table from the Visual FoxPro SAMPLES\DATA
directory, you could focus on customers residing in the United States by entering the
following expression in the Data Filter box:
Customer.Country = "USA"

Results of filtering a table

TEES
= EN S

d Market

jattlesnake Canyon Grocery

Only records from the USA are shown.

Restricting Access to Fields


If you want to keep certain fields from displaying when tables are browsed or used in
a form, you can set a field filter to restrict access to those fields. You select the fields
you want to display, which leaves the remaining fields inaccessible.

> To set a field filter


1 From the Table menu, choose Properties.
2 Inthe Work Area Properties dialog box, under Allow access to, select Only
fields specified by ‘field filter' and choose Field Filter.
3 Inthe Field Picker dialog box, add the fields you want to the Selected fields
column and choose OK.

User’s Guide 29
Part 1 Organizing Information

Field filter and its effect on a Browse window

elected fi When you set a field filter


a.customer_id by selecting the fields you
want to display, the Browse
window shows only the
selected fields.

When you browse the table, only fields you selected in the field filter are displayed.
For more information about customizing and working with tables, see Chapter 7,
“Working with Tables,” in the Developer's Guide.

Ordering Data Using Indexes


Once you create a table, you can order the data to speed up data retrieval by using
indexes. With indexes, you can quickly process your records for displaying, querying,
or printing. You can also select records, control whether duplicate values are entered
in a field, and support relationships between tables.
You can use indexes to increase the speed that records are sorted or searched for
display or printing. Indexes are also important for creating relationships between
tables in a database.

Indexes in Visual FoxPro are like book indexes: a list of page numbers that points the
reader to specific pages in a book. Likewise, a table index is a list of record numbers
that points to specific records to process and determines the processing order for the
records.

30 User’s Guide
Chapter 2 Creating Tables and Indexes

A table index stores a list of pointers to records.

Customer
Company Name
001 WELLI Wellington Importadora
002 MAISD Maison Dewey The records stored
003 BOTTM Bottom-Dollar Markets in the table...
004 SEVES Seven Seas Imports
005 BNAP Bon app'
Around the Horn

Customer a -

Company Name
Around the Horn
...are selected
Bon app'
and ordered by Bottom-Dollar Markets
the active index... Great Lakes Food Market
Maison Dewey
Seven Seas Imports
Wellington Importadora ...for display.

For example, you can look at the records in the Customer table in alphabetical order
by company name, prepare them for a mailing list in order by postal code, or organize
them to speed up searches. The index does not change the order that data is stored in
your table; it changes the order that Visual FoxPro uses to read each record.
You can create more than one index for a table, each representing a different order for
processing your records. The indexes you create are stored in a compound structural
index file that is opened and updated whenever the table is used. The name for the
index file is the same as its associated table and has a .CDX file extension.
Indexes are so easy to create, you might be tempted to define one for every field.
However, indexes that you use only rarely can slow performance. Other types of index
files are better for storing indexes you don’t use regularly. For more information about
the other kinds of index files available to you, see Chapter 7, “Working with Tables,”
in the Developer’s Guide.

Creating an Index
Once you have a table, you can create an index on a field or on an expression. To use
indexes efficiently, create indexes on fields you often use in filters on tables, in
queries, in views, or for reports. If you place an index on a field that isn't useful for
filtering or querying, such as a street address, your filter might slow down processing.

> To create an index


1 Inthe Project Manager, select the table you want to add an index to, then choose
Modify.
2 Inthe Table Designer, select the Indexes tab.

User’s Guide 31
Part 1 Organizing Information

The Indexes tab in the Table Designer

ad aan ah : sons Click here to enter a


COMPANY. Eel/company | condition for record
f . CONTACT Regular contact ey selection.
Click hereto sortin = [| | =PosTaLcoot Regular | postalcade SS
ascending or \ CUST_ID Primary! cust_id
descending order. COUNTRY — Regular UPPER [coun
Click here to delete
Enter a new the index.
index here.

Click here to set an Click here to enter an


index type. index expression.

In the Name box, type a name for the index.


From the Type list, select an index type.
For more information about index types, see the following section, “Choosing an
Index Type.”
5 In the Expression box, type the name of the field you want to order the records by.
E@r
Build an expression by choosing the dialog button at the end of the box to display
the Expression Builder.
For information about adding multiple fields to your index expression, see the
following section, “Ordering by Multiple Fields.”
6 If you want to select records, enter a filter expression in the Filter box or select the
button at the end of the box to build an expression.
For more information about using a filtered index, see the section, “Filtering
Records,” later in this chapter.
7 Choose OK.

Once you create an index for the table, you can use it to order your records.

> To order records using an index


1 In the Project Manager, select the table with the index you created.
Choose Browse.
From the Table menu, choose Properties.
In the Index order box, select the index you want to use.
Choose OK.

32 User’s Guide
Chapter 2 Creating Tables and Indexes

The table appears in the Browse window, displaying the records in the order your
index specifies. You can also order the results of queries or reports by running them
while the index is selected.

Choosing an Index Type


You can choose one of four types of indexes:
¢ Primary
¢ Candidate
¢ Regular
* Unique

Primary indexes ensure only unique values are entered into a field and determine the
order in which the records are processed. You can create one primary index for each
table if the table is included in a database. If the table already has a primary index, add
a candidate index.
Candidate indexes also enforce unique values and determine the order in which the
records are processed, like a primary index. You can have multiple candidate indexes
per table in both database and free tables.
Regular indexes determine the order in which records are processed but allow
duplicate values to be entered into a field. You can add more than one regular index to
a table.
For compatibility with previous versions, you can also create a unique index that
selects and orders a subset of records based on the first occurrence of a value in the
field you specify. If you want to select records this way, you might want to create a
query or view instead. For more information about queries or views, see Chapter 4,
“Retrieving Data,” or Chapter 5, “Updating Data with Views.”

Ordering by Multiple Fields


To increase the speed of queries or views that have filters on more than one field, you
can order your records by specifying multiple fields in the index expression. The
fields are evaluated in the same order they appear in the expression. If you create an
index expression using numeric fields, the index orders the records by the sum of the
fields, not the fields themselves.

> To order records using multiple fields


1 In the Project Manager, select the table you want to add an index to and choose
Modify.
2 In the Indexes tab, enter a name and type for the index.
3 Inthe Expression box, enter an expression that lists the fields you want to order
by.

User’s Guide 33
Part 1 Organizing Information

For example, you might want to order the records by country, postal code within
the country, and the company name within the postal code. You can use a plus sign
(+) to create the index expression from character fields.
customer.country + customer.postalcode + customer.company

Notice that the field that changes the least is the first one in the list.
4 Choose OK.

If you want to use fields of different data types, you can convert the non-character
fields to characters by enclosing the field with STR( ). For example, you can try
ordering the records by the Maximum Order Amount field, then by the company
name. In this expression, maxordamt is a Currency field and company is a Character
field.
STR(customer.maxordamt,20,4) + customer.company

Filtering Records
You can control which records are included in the index by adding a filter expression.

> To filter records


1 Inthe Project Manager, select the table you want to add an index to and choose
Modify.
In the Indexes tab, create or select an index.
3 In the Filter box, enter a filter expression.
For example, try creating a filter that selects only the records for customers in
Canada:
customer.country = "Canada"

4 Choose OK.

Using Indexes
You can improve performance by creating and using indexes for recurring tasks such
as ordering your records or supporting table relationships. You can accomplish several
tasks depending on the type of index you create.
If you want to Use
Order the records to increase the speed they are A regular, candidate, or primary index.
displayed, queried, or printed
Control entry of duplicate values in a field and A primary or candidate index for a database
order the records table or a candidate index for a free table.

34 User’s Guide
Chapter 2 Creating Tables and Indexes

Ordering Your Records


You can order your records by a field name or another index expression. The index
evaluates the expression to determine the order that the records should appear, then
stores a list of pointers to the records for processing in that order.

> To create an index for ordering records


1 In the Project Manager, select the table you want to add an index to and choose
Modify.
In the Indexes tab, enter a name and type for the index.
In the Expression column, type the field name you want to use to order the
records.
_—Or-
Type an expression you want to use to order the records or build an expression by
choosing the button at the end of the box to display the Expression Builder.
4 If you want the records to appear in descending order, select the arrow button to the
left of the index name.
The arrow on the button points down for descending order and up for ascending.
5 Choose OK.

Controlling Entry of Duplicate Values in a Field


You might want to control entry of duplicate values in a field. For example, each
customer should have a unique value in the Cust_ID field of the Customer table.

An index can enforce entering unique values into a field.

Data Entry
FE ~
EnteranID for the customer: VAF The value entered...

.../S Compared with


values in the index to
prevent duplicate values.

You can use the field as a key field that uniquely identifies a record. If your table is
part of a database, you can use either a primary or candidate index. If your table is a
free table or already has a primary index, you must use a candidate index.

User’s Guide 35
Part 1 Organizing Information

> To create an index that enforces unique values ina field


1 In the Project Manager, select the table you want to add an index
to and choose
Modify.
2 In the Indexes tab, create an index.
3 In the Type column, select Primary or Candidate.
4 Choose OK.

36 User’s Guide
CHAPTER 3

Collecting Tables into a Database

Tables, used individually, are helpful for storing and viewing the information you
work with. But if you organize your tables into a database, you can tap more of the
power of Visual FoxPro. By putting your tables into a database, you can reduce
storage of redundant data and protect the integrity of your data. For example, you do
not have to repeatedly store the name and address of a customer for each order that the
customer has placed. You can store the customer’s name and address in one table and
relate that information to orders stored in another table. If the customer’s address
changes, you only need to update one record. You can control how fields are
displayed or what values may be entered into fields. You can also add views and
connections to a database for updating records or expanding your access to remote
data.
This chapter explains the basics: incorporating tables or views into a database, setting
relationships between tables, and controlling data entry and other properties for
database tables. Databases, the process of database design, and the use of database
table properties are covered in more detail in Chapter 5, “Designing Databases,” and
Chapter 6, “Creating Databases,” in the Developer’s Guide.
This chapter discusses:
¢ Working with a Database
¢ Creating a New Database
¢ Defining Field Display
* Controlling Data Entry in a Field
* Controlling Data Entry in a Record
¢ Managing Records in a Database

User’s Guide 37
Part 1 Organizing Information

Working with a Database


A database provides a working environment where you can store a collection of
tables, establish relationships between the tables, and set properties and data
validation rules that control how the related tables work together. A database is stored
as a file with a .DBC extension.

Contents of a database

sees
‘ault>

a : a reduc :
Fields: Fields: FFields:
cust_id | product_id line_no
company prod_name order_id
contact eng_name : product_id
title no_in_unit unit_price
address : quanttit:

Ra
(| Fields:
order_id emp_id
cust_id | last_name company
emp_id first_name contact
to_name i | title
to_addess | _ birth address

product_id
.| Customer Information
prod_name
product_id eng_name
unit_price no_in_unit
PEEPLES SCLOE DEEP LEIP IO ODO LE LO EEE
LLL ILE SELB | A ate pice

You can use databases independently or incorporate them into a project by adding
them to the Project Manager. To access the tables within a database, the database must
be open.

38 User’s Guide
Chapter 3 Collecting Tables into a Database

> To open a database


1 In the Project Manager, select the name of the database you want to use.
2 Choose Modify.

You can also choose Open from the File menu and choose the name of a database.
To look at the structure of a sample database, try opening TESTDATA.DBC, which is
found in the SAMPLES\DATA subdirectory where you installed Visual FoxPro.
When you open a database, the Database Designer appears, showing you the tables
that make up the database, and the relationships between them.

Tables in the Database Designer


I rif, Database Designer z Testdata

Fields: EFF ields: ! ields:


| emp_id or y line_no
last_name company order_id
first_name contact product_id .
title 4 title
birthdate address

fo z
Fields: ESFields: 1E Fields
orderid | yy product_id | custLid_a
cust_id prod_name , compari
emp_id eng_name contact
to_name no_in_unit title
to address unit_price addre

Boxes display the fields and Relationship lines show


indexes in each table. joins between tables.

The Database Designer toolbar displays so that you can quickly access database-
related options. Database commands are available on the Database menu; you can also
display shortcut menus by clicking the right mouse button in the Database Designer.
You can resize the tables in the Database Designer to see more or less of the fields and
the indexes they contain, or collapse the table to show only the table names, which is
helpful if your database contains many tables.

> To expand or collapse a single table


1 Place the pointer on a table in the Database Designer and click the right mouse
button.
2 Choose Expand or Collapse.

> To expand or collapse all the tables


1 Place the pointer in the Database Designer and click the right mouse button.
2 Choose Expand All or Collapse All.

User’s Guide 39
Part 1 Organizing Information

Collapsed view of tables in a database

You can change the layout of your tables displayed in the Database Designer. For
example, after working in the database, you might want to return the tables to the
default height and width or you might want to improve the layout by aligning the
tables.

> To arrange the tables in a database


¢ From the Database menu, choose Arrange, and then select the appropriate options
in the Find Table or View dialog box.
In the Database Designer, the title bar of the table you selected is highlighted.
To Select
Arrange the tables alphabetically by name By name
Arrange the tables by type By type
Align the tables in a row Horizontally
Align the tables in a column Vertically
Return the tables to their original size Resize objects to default height and width

To keep notes about the database, you can add a comment.

> To add a comment to a database


¢ From the Database menu, choose Properties, and then type your comment in the
Comment box.

Creating a New Database


To incorporate your data into a database, first create a new database, then add the
tables you want to work with and define the relationships between them. You can also
create new local or remote views from within the Database Designer to incorporate
them into your database.

> To create a new database


1 In the Project Manager, select Databases.
2 Choose New.

When you create a new database, an empty Database Designer window is displayed,
along with the Database Designer toolbar.

40 User’s Guide
Chapter 3 Collecting Tables into a Database

A new database in the Database Designer

Adding Tables to a Database


Begin building your database by adding the tables you want to use. You can select any
table that is not currently part of another database. Since tables can only belong to one
database at a time, you need to remove a table from a database before you can use it in
a new database.

> To add a table to a database


1 From the Database menu, choose Add Table.
2 In the Open dialog box, select a table and choose OK.

You can remove a table from a database if it is no longer needed, or if you need to use
it in another database.

> To remove a table from a database


1 Select the table.
2 From the Database menu, choose Remove.
3 In the dialog box, choose Remove.

Creating and Adding Views


Views display records from one or more tables and can be used to update those source
tables. If you want to add a local view to your database, you can create one from the
tables or views currently contained in your database, or from free tables outside your
database. If the information you need is on a remote data source, you can create a
remote view from it and incorporate that view into your database.
Because views exist only within the context of a database, you must create a view
within your database in order to incorporate it into your database.
For information about creating local or remote views, see Chapter 5, “Updating Data
with Views.”

User’s Guide 41
Part 1 Organizing Information

Finding a Table or View in a Database


If your database has many tables and views, you might want to quickly locate a
specific table. You can use the Find command to highlight the table or view you want
to work with.

> To find a table in a database


¢ From the Database menu, choose Find Object, and then select the table you want
to find in the Find Table or View dialog box.

If you want to show only the tables or only certain views, you can choose to display
only tables or certain views.

> To display only the tables or views


¢ From the Database menu, choose Properties, and then select the appropriate
display options in the Database Properties dialog box.

Relating Tables
The Database Designer makes it easy to create relationships between tables by linking
their indexes. The relationships you create in a database are called persistent
relationships, because they are stored as part of the database. Each time you use the
tables in the Query or View Designers, or in the Data Environment Designer when
creating forms, these persistent relationships appear as default links or joins between
the tables.

Preparing for Relationships


Before you can create a relationship between tables, the tables you want to relate need
to have certain fields and indexes in common. The fields are called primary and
foreign key fields. The primary key field identifies a specific record within a table.
The foreign key field identifies the related records that reside in another table within
the database. You also need to add a primary index to a primary key field and a
regular index to a foreign key field.

42 User’s Guide
Chapter 3 Collecting Tables into a Database

Indexes to support a relationship between two tables

lBa ee oF :
E order_id
customer_id customer_id
company_name shipper_id &
pecawer ae =~ Because these tables have
contact_title arder_date _|__ this field in common...
address ship_to_name ae
city ship_to_address
region ship_to_city -
postal_code ship_to_region \
country ship_to_postal_code —
phone ship_to_country |
fax discount S
max_order_amt freight .
min_order_amt deliver_by .
discount notes :
sales_fegion employee_id q
(Elindeves: |C2indexes: LD
company_na shipper_id
_| ®customer_i customer
:1
employee_i
ordernumb ...you can add indexes to support
Yorder_id
cust_ord
a relationship between the tables.

To determine which tables need the fields, think about how your data is related by
number of records. For example, one customer can have many orders. So, the
customer table holds the primary records and the orders table has the related records.
To prepare the primary table for a relationship to the table with the related records,
you need to add a primary key field to the primary table, which in our example is
Customers. You know this because the Customer table will contain one record for
many related records in the Orders table.
To provide a common field between the two tables, you need to add a foreign key
field to the table with the related records, which in our example is the Orders table.
The foreign key field should match the primary key field with the same data type and
usually the same name as the primary key field. The indexes you create on the primary
and foreign key fields should have the same expression.
For more information about primary key fields, foreign key fields, and relationships,
see Chapter 7, “Working with Databases,” in the Developer's Guide.

> To prepare for relationships


1 Determine which table has the primary records and which table has the related
records.
2 To the table with the primary record, add an integer field, then add a primary index
on the new field.
3 To the table with the related records, add a field that matches the primary key in the
other table, then add a regular index on that new field.

User’s Guide 43
Part 1 Organizing Information

Note Use the same expression for both indexes. For example, if you use a function in the
expression on the primary key field, you need to use the same function in the expression on
the foreign key field.

Creating and Editing Relationships


With the key fields and indexes defined, you are now ready to create a relationship. If
your tables are not already indexed, you need to open them in the Table Designer and
add indexes to them. For information on indexing tables, see Chapter 2, “Creating
Tables and Indexes.”

> To create a relationship between tables


¢ Drag from the index in one table to the matching index in another table.

Once you set the relationship, you see a line connecting the two tables in the Database
Designer.

Note You can only see relationship lines if the Relations option in the Database Properties
dialog box is turned on. You can access the Database Properties dialog box by choosing
Properties from the shortcut menu in the Database Designer.

Line shows the relationship between two tables.

-Datal

ytdpurch
lat
lona
cng
CAlindexes:

You can also edit the relationship.

> To edit a relationship between tables


* Double-click the relationship line between the tables, and then select the
appropriate settings in the Edit Relationship dialog box.

44 User’s Guide
Chapter 3 Collecting Tables into a Database

Edit Relationship dialog box


Edit Relationship

The type of relationship created is determined by the type of index used on the child
table. For example, if the index on the child table is a primary or candidate index, the
relation is one-to-one; otherwise (for unique and regular indexes) it is a one-to-many
relationship.

When you add tables to a database, you can immediately take advantage of additional
properties not available when working with free tables. These properties are stored as
part of the database, and remain with the table only as long as it belongs to the
database.
Using properties for fields in a database table, you can:
¢ Assign captions to fields.
¢ Enter comments about the purpose of a field.
¢ Set default values for fields.
¢ Set an input mask and display format for a field.
¢ Set a control class and library for a field.
¢ Set validation rules to restrict the data that can be entered in a field.

The following sections describe some of these properties. You can find more
information in Chapter 7, “Working with Tables,” in the Developer's Guide.

Setting a Field Caption


You can display descriptive labels for fields you display in the Browse window or on
your forms by using field captions.

> To assign a caption to a field


1 Select the table in the Database Designer and choose Modify.
2 Select the field you want to assign the caption to.
3 In the Caption box, type the caption you want displayed for the field.
4 Choose OK.

User’s Guide 45
Part 1 Organizing Information

For example, if the name of a field is Cust_ID, you can add a caption such as
“Customer ID” to the field. Each time you browse the table, use the field in a query or
view, or add the field to a form; you see the caption instead of the field name as a label
for the field.

Column name based on caption


REToTAEIEOT
PI OT QO FAW
\/Displa

[Customer —-« Enter the caption here and it


appears in the Browse window.

freds Futterkiste

Entering Comments for a Field


As you set up the structure of your tables, you may want to enter notes or comments
to remind you or others of what the table field represents. You can annotate each field
by typing a message in the Field Comment box in the Table Designer.

Comments clarify the purpose of a field.

> To add a comment to a field


1 In the Table Designer, select the field.
2 Inthe Field Comment box, type your comment.
3 Choose OK.

Controlling Data Entry in a Field


You can make data entry into your table easier by supplying default values for fields
and by defining validation rules for values entered into fields.

46 User’s Guide
Chapter 3 Collecting Tables into a Database

Setting Default Field Values


If you want to have a value entered into a field automatically whenever you create a
new record, you can set a default value for that field using the field properties in the
Table Designer. For example, if most of your sales come from one particular region,
you might want to set that region as the default value for the region field.

> To set a default value for a field


1 In the Database Designer, select the table.
2 From the Database menu, choose Modify.
3 Inthe Table Designer, select the field you want to assign the default value to.
4 In the Default value box, type the field value you want displayed in all new
records (enclose character fields in quotes).
5 Choose OK.

For example, you might want all new records in a Products table to have a default
“reorder at” setting of 15 units.

Setting a default value for a field

it_cost 26.3500
/) |Prod_namelkura
| |Eng_name Fish Roe
| |No_in_unit 12 - 200 mil jars
31.000

| |Reorder_at15.000
Discontinu F

Setting Validation Rules and Validation Text


By entering a validation rule for a field when defining the structure of a table, you can
control the type of entry that can be made to that field. For example, you could restrict
the acceptable entries for a field to a list of states, open purchase order numbers, valid
ID numbers, and so on.

User’s Guide 47
Part 1 Organizing Information

> To set a validation rule and validation text for a field


1 Open a table in the Table Designer.
2 In the Table Designer, select the name of the field you want to set a rule for.
3 Choose the dialog button next to the Rule box.
4 Inthe Expression Builder, set up the validation expression and choose OK.
5 Inthe Message box, type the error message in quotes.
6 Choose OK.

For example, try creating a simple address table and restricting the entries in the
Country field to “UK” or “USA.”
Customer.country = "UK" OR Customer.country = "USA"

You can also specify the message to display if the validation rule is not met. For
example, you could display this message:
"Country must be USA or UK. Please reenter value."

When creating your validation rule, you must create a valid Visual FoxPro expression
that takes into account the field length, that a field can either be empty or contain the
desired value, and so on. Your expression may include functions if the functions
evaluate to true or false.

For example, assume you are using the Customer table from SAMPLES\DATA, and
you want to be sure that any new customer ID codes are less than 6 characters long. In
the Validation Rule box for the Cust_ID field, you could enter:
LENCALLTRIM(CUST_ID)) < 6

Then, in the Validation Text box, you would enter this error prompt:
"Customer ID must be less than 6 characters. Please reenter."

If you try to enter a customer ID that is too long, the validation text appears in a dialog
box.

Validation text appears when incorrect value is entered.


oe at Enter the validation rule here.

—=7— Enter the error message here.

The error message


displays if the entry is invalid. ]

Revat |

48 User’s Guide
Chapter 3 Collecting Tables into a Database

Controlling Data Entry in a Record


Just as you can assign database properties to the individual fields within a table, you
can set properties which apply to the entire table, or to the records within a table. In
the Table Designer, you access these properties on the Table tab.

Setting a Validation Rule for a Table


If you want two or more fields to be compared, or to meet a certain condition as
records are entered into a table, you can set a validation rule for the table.

> To set a validation rule


1 Select the table and choose Modify.
2 Inthe Table Designer, choose the Table tab.
3 In the Rule box, enter a valid Visual FoxPro expression that defines the rule.
Choose the dialog button to use the Expression Builder.
4 In the Message box, enter the prompt you want to be displayed if the rule is
broken.
5 Choose OK.
6 Inthe Table Designer, choose OK.

For example, assume you are using the Customer table found in SAMPLES\DATA,
and don’t want customer orders from the state of Washington to exceed $10,000. You
can enforce this rule by typing the following expression into the Validation Rule box
in the Table tab:
II1F(Customer.region = "WA" and Customer.maxordamt > 10000, .F.,.T.)

The Message Text value could be something like:


"Orders from WA state customers cannot exceed $10,000"

User’s Guide 49
Part 1 Organizing Information

Entry rejected based on validation rule.


Table Designer - customer.
dbf

4IIFfCustom
: Ss Validation rule and error
2 [Orde from WA, stat message for table.

bleC Error message displays


{Customer Information if rule is not met.

Setting a Trigger
Triggers are expressions that activate whenever a record is inserted, deleted, or
updated in the table. Usually, triggers involve writing a program, or stored procedure,
that is activated when the table is changed. For more information about triggers, see
“Using Triggers” in Chapter 7, “Working with Tables,” in the Developer’s Guide.

Managing Records in a Database


After establishing relationships, you can also set rules for managing the related
records in your database. These rules govern referential integrity. For example, if you
add a supplier record, you might want to automatically add information about the
supplier's products to the Products table. To help you set up rules to control how
records are inserted, updated, or deleted in related tables, you can use the Referential
Integrity Builder.

50 User’s Guide
Chapter 3 Collecting Tables into a Database

Referential Integrity button in Edit Relationship dialog box


&s Edit Relationship

> To use the Referential Integrity Builder


1 In the Database Designer, create a relationship between two tables, or double-
click the relationship line to edit the relationship.
In the Edit Relationship dialog box, choose the Referential Integrity button.
3 In the Referential Integrity Builder, select the rules you want to enforce for
updating, deleting, or inserting records.
4 Choose OK, and then choose Yes to save your changes, generate RI code, and exit
the builder.

User’s Guide 51
ie eee oe a
rmHh apa
aD agegat
- ise ae Steak and ) eae enn

am en ri

mae tee cdee we


elie: Pa
ge)
a a a
PART 2

Finding Information

When you need answers fast, Visual FoxPro makes it easy to search
your tables and databases to find just the information you need.

Chapter 4 Retrieving Data


Queries help you get the answers you need from your data. Here
you'll learn about the Query Designer and how to create a basic,
one-table query.

Chapter 5 Updating Data with Views


Views enable you to extract a set of records from local or remote
tables. You can use a view to work with and update the records you
retrieve, and have Visual FoxPro send your changes to the source
tables.

Chapter 6 Querying and Updating Multiple Tables


You can take advantage of the full power of queries and views when
you run queries against multiple tables, whether they reside locally
or on a remote server. You’ll learn how to create multi-table queries
and views, and how to use remote views in queries.

User's Guide 53
, %

ihaticas Ayaka diaaa ay taal as eawene sstaiad ani


dean cpeiONAN Ir at cede briggallate

‘i<n . Peace 4 ae
= pt ak c iheady: na 6 apybiowen whWedsh:

‘pe ; ~s
SAS) icVise peal tke tp tay 3 eee) Py
io Er:
voy *brover atl) Siabeyhas Wiw show oF wore
poy 7
sensors ihe ut cage mci! orixaot
d ae

7.
ee ssl qncibetswngieiee:venmait >—
teddy avrg Hig shay We ita Het oto awaits oat mae
vise! liSai
om aathor! 4 ested afqinhasn: lage oheg
patron ia ialaiine gnats dg eeod sesh aunp
iroy
wo a
= Tie tea Mors
SS

— - Ss~

be shit atmatl a
CHAPTER 4

Retrieving Data

When you need answers quickly, use the Query Designer to retrieve the information
stored in your tables and views. For example, you might need to know the answers to
questions like:
¢ What customer name and address is associated with a particular ID number?
* How many orders are outstanding?
¢ How many customers have overdue balances?
¢ Which region or salesperson has the best sales record?

With the Query Designer, you can search for records that meet the criteria you specify.
You can also order and group the records as needed, and create reports, tables, and
graphs based on the results.
This chapter describes how to create and work with simple read-only queries based on
tables (.DBF files) or views. For information about working with multi-table local
queries or remote data, see Chapter 6, “Querying and Updating Multiple Tables.” For
information about creating views, see Chapter 5, “Updating Data with Views.”
This chapter discusses:
¢ Creating a Query
* Defining Your Results
¢ Organizing Your Results
¢ Running a Query
* Customizing Queries

User’s Guide 55
Part 2 Finding Information

Creating a Query
You may want to create queries for various reasons: to organize information for a
report, to answer a quick question, or to see any relevant subset of your data.
Whatever your aim, the basic process of creating a query is the same.
Using the Query Designer, you select the table or view you want information from,
specify the criteria to extract records from the table or view, and then direct the results
of your query to the type of output you want, such as a browse window, report, table,
label, and so on. When you’ve created a query you want to keep, you can save it by
giving it a name. Queries are stored as files with a .QPR extension.

The query design process

¢ Highest sales?
“2 __ Best Customers in Region?

| CUSTOMER.SALES > $1,000

A CUSTOMER.CUST_ID
CUSTOMER.REGION A CUSTOMER.REGION
CUSTOMER.SALES A CUSTOMER.SALES

®@
Run Query Browse

After you have decided what information you need to find, and what table or view it is
stored in, you’ll go through the following general steps when creating queries:
1. Start creating the query with a query wizard or the Query Designer.
2. Select the table or view that holds the information you want to retrieve.

56 User’s Guide
Chapter 4 Retrieving Data

3. Define your query results by choosing which fields you want, the order you want
the fields to appear, and the records you want.
4. Organize your query results by ordering and grouping the rows in the results.
5. Choose the type of output you want for the query: table, report, browse, and so on.
6. Run and verify the query.

Using a Query Wizard


If you want help creating a query quickly, use one of the Visual FoxPro query
wizards. A query wizard asks you in which tables or views you want to search for
information, and sets up a query based on your answers to a series of questions.
For more information about the query wizards, press F1 for Help while you are using
the wizard.

> To create a query with a wizard


1 In the Project Manager, select the Data tab and choose Queries.
2 Choose New.
3 Choose the Query Wizard button.
4 Select the type of query you want to create.
5 Follow the instructions on the wizard screens.

You can also choose Wizards on the Tools menu to start a wizard.

Starting the Query Designer


If you don’t want to use a query wizard, you can use the Query Designer to create
your query. You can start the Query Designer from the Project Manager or from the
File menu.

> To start the Query Designer


1 Inthe Project Manager, select the Data tab.
2 Select Queries.
3 Choose New.
4 Choose New Query.

You can also start the Query Designer by choosing New from the File menu, selecting
the Query option, and selecting New File.
When you create a new query, you will be prompted to select a table or view from the
current database or from a free table.

User’s Guide 57
Part 2 Finding Information

Selecting a table or view to query

Select the database you


Select the view ortable want to use.
you want to query. ——

Choose this button if you want


to use a table that is not part
of a database.

After you select a table or view, Visual FoxPro displays the Query Designer window.

The Query Designer window

Employee

last_name
first_name
title
bith_date

You can easily change to a different table or view.

> To use a different table or view


1 Select the current table and choose the Remove Table button on the Query
Designer toolbar.
2 From the Query Designer toolbar, choose the Add button, and then select the table
or view you want.

58 User’s Guide
Chapter 4 Retrieving Data

Defining Your Results


After you have opened the Query Designer and selected the table or view that
contains the information you want, you can define your results. At a minimum, you
need to select the fields you want. You can also define your results by setting the order
the selected fields appear and setting filters to select which records appear.

Selecting Fields You Want


Before you can run a query, you must select some fields to include in the results. In
some cases, you might want to use all the fields from the table or view. At other times,
you might want to focus the query on a few selected fields, such as fields you want to
include in a report.
Be sure to include any fields you might want to use to sort or group the results of your
query. When you select the fields, you can also set the order they appear in your
output.

Use the Fields tab in the lower pane of the Query Designer to select the fields you
want to include in the results of your query.

The Fields tab in the Query Designer

shefe

Employee.emp
ig
nplayee. jast_name
Employee first_narme
— {Employee title
~ {Employee. birth_date
. Employee. hire_date

> To add a field to the query output


¢ Select the name of the field and choose Add.
Ore
¢ Drag the field name to the Selected fields box.

Selecting All Fields for Output


You can select all of the fields by name or use the asterisk wild card. If you select the
fields by name, the exact names of the fields are included in the query. If you run the
query after adding fields to the table, the new fields are not included in the results.
If you use the wild card, the asterisk is included in the query and includes all fields
that are in the table at the time of the query. If the table structure has changed since the
query was created, the new fields also appear in the query results.

User’s Guide 59
Part 2. Finding Information

> To add all available fields to a query at once


¢ Choose Add All to add fields by name.
2Or
* Drag the asterisk at the top of the table into the Selected fields box.

Displaying an Alias for a Field


You can make your query results easier to read and understand by adding a descriptive
caption to a results field. For example, you might want to display the word
“SumMaxOrd” at the top of the results column instead of the field name or
expression, SUM(MaxOrdAmount).

> To add an alias for a field


1 In the Functions and expressions box, type the field name, and then type AS and
the alias, as in this example:
SUM(maxorderamt) AS SumMaxOrd
2 Choose Add to place the field with the alias in the Selected fields box.

Setting the Order for Output Fields


The order that fields appear in the Fields tab determines the order of the columns of
information in your query output.

Setting the order of output columns


Pipette:

ployee.emp_id
Empl a

Drag the mover box to


set field order.

> To change the column order of the query output


* Drag the mover box, located to the left of a field name, up or down.

If you want to change the order that rows of information will be sorted, use the Order
By tab instead.

60 User’s Guide
Chapter 4 Retrieving Data

Selecting the Records You Want


Selecting the records you want to find is the key step that determines the results of
your query. With the Filter tab in the Query Designer, you can formulate the WHERE
clause of a select statement to tell Visual FoxPro which records to search for and
retrieve.

You may want to find a specific subset of data to include in a report or other output:
for example, all customers with outstanding balances, all customers in a specific
region or postal code, and so on. To see only the records you want, enter a value or
range of values to compare the records against.
In Visual FoxPro, you use the Filter tab to specify which field you want to use for
selecting records, choose a comparison criterion, and enter an example of the value
you want the field to be compared to.

Defining criteria for query results

Enter the comparison


value here.

Select the field you Select the type of


want to compare. comparison.

> To specify a filter


1 From the Field Name list, choose a field you want to use as the basis for selecting
records.
Note You can’t use General or Memo fields in a filter.

From the Criteria list, choose the type of comparison to use.


Enter the comparison criterion in the Example box.
* Use quotation marks only if the string is the same as the name of a field in a
table in the query; otherwise, do not enclose character strings in quotation
marks.
* If you use dates, do not enclose them in braces.
* Place a period before and after a logical literal (.T.).
* If you enter a field name from a table in the query, Visual FoxPro will recognize
it as a field.

User’s Guide 61
Part 2 Finding Information

4 If you want capitalization to be ignored in searches on character data, select the


Case button.
If you want to reverse the meaning of a logical operator, select the Not button. For
example, if you want to find customers in all regions except Washington, use the
selection expression in the following example:
Customer.region Not Like WA

To further tune your search, you can add more filters in the Filter tab. For more
information, see the section, “Fine Tuning Your Search,” later in this chapter.

If you are using more than one table or view in your query, you can expand the
records you select by the join type you choose. For more information about joins, see
Chapter 8, “Creating Views,” in the Developer's Guide.

Organizing Your Results


With the output of your query defined, you can now organize the records that appear
in your results by ordering and grouping on the output fields. If you want, you can
also filter the groups that appear in your results.

Ordering Query Results


Ordering determines the order in which records or rows will be sorted when they
appear in the output of your query. For example, you could sort records by State and
then by City, or sort them in ascending order based on the outstanding account
balance.
Use the Order By tab to set the sort order for your query. The sort order determines
the order in which rows or records will appear in your query output.
First select the fields you want to use from the Selected Fields box and move them to
the Ordering Criteria box. Then arrange the fields in the order you want them to
appear in the query results.

> To set ordering criteria


1 In the Selected fields box, select a field name.
2 Choose Add.

> To remove ordering criteria


1 Select one or more fields that you want to remove.
2 Choose Remove.

The order in which fields appear in the Ordering criteria box determines the order of
importance when the query results are sorted. The first field determines the primary
sort order.

62 User’s Guide
Chapter 4 Retrieving Data

For example, if the first field in the Ordering criteria box is Customer. region and
the second field in the Ordering criteria box is Customer.city, the results will be
ordered by Customer. region. If more than one record in the customer table has the
same region field value, these records are additionally ordered by Customer.city.

Setting sort order with the Order By tab

ae :
ustomer.cust_id
ustomer.company ‘ : With the criteria
in this order...

..the query sorts records by


region and then by city.

To adjust the importance of a sort order field, use the button to the left of the field to
drag the field to the desired location in the Ordering criteria box.
You can sort in ascending or descending order by setting the buttons in the Order
options area. Each order field appears in the Output fields box on the Filter tab with
an up arrow or down arrow next to it, indicating whether the sort on that field is to be
made in ascending or descending order.

Grouping Query Results


Grouping consolidates or gathers similar records into one record so you can perform
calculations based on groups of records. For example, you might want to find the sum
of all orders to a specific region. Instead of looking at all the records individually, you
can group all the records from the same region into one record, and get the sum of all
the orders from that region. To control how records are grouped, use the Group By tab
in the Query Designer.
Grouping is most useful when used in conjunction with an aggregate function, such as
SUM, COUNT, AVG, and so on.
For example, suppose you want to see the total dollar amount of orders for each
customer ID number in your orders table. You need to group all the order records for a
given customer ID into one record, and find the sum of the order amounts.
You first use the Fields tab to add the expression SUM(Orders.order_net) to the output
of your query, then use the Group By tab to group the results by customer ID number.
The results show total net orders for each customer:

User’s Guide 63
Part 2 Finding Information

Setting Group By options

Use the Functions/Expressions box on


the Fields tab to create the expression.

Use the Group By tab to


group the results by
customer ID number.

__|Cust_id| Sum_order_net |

The results show the total net order


amounts grouped by customer.

> To set grouping options


1 In the Fields tab, type the expression in the Functions and expressions box.
—Or=
Choose the dialog button to use the Expression Builder to enter an expression in
the Functions and expressions box.
2 Choose the Add button to place the expression in the Selected fields box.
3 In the Group By tab, add the expression to group results by.

You can also set a filter on the grouped results.

Selecting the Groups You Want


To set a filter on grouped or consolidated records rather than on individual records,
choose Having on the Group By tab. You can use a field name, an aggregate function
on a field name, or another expression in the Field Name box.

Building on the previous example, you could use the query that shows total sales by
customer number, then use the Having button to restrict the output to customers
having more than $50,000 in net orders:

64 User’s Guide
Chapter 4 Retrieving Data

Setting criteria for a group


Having
Eee

The Having option


lets you set a
criteria on a group
of records.

id| Sum_order_net _
113683.7570

The results show customers with total


net orders greater than $50,000.

> To set a Having option on a group


1 In the Group By tab, choose Having.
2 In the Having dialog box, select a function and field name in the Field Name field.
3 Choose OK.

Running Your Query


When you have finished designing your query, you can start the query by choosing the
Run button. Visual FoxPro executes the SQL select statement you built with the
Query Designer, and sends the results to a Browse window.

> Torun a query


¢ In the Project Manager, select the name of the query, then choose Run.

If you want your results to go to a different destination, you can direct your results to
a form, table, report, or other destinations. If you like to know what the SQL
statement looks like, you can view the SQL statement that you built.

For more information on the SELECT-SQL command, see Help.

Directing the Results of Your Query


You can send the results of your query to different destinations. If you have not
selected an output destination, the results of your query will be shown in a Browse
window.

User’s Guide 65
Part 2 Finding Information

When you choose Query Destination on the Query menu, or choose the Query
Destination button on the Query toolbar, the Destination dialog box displays, so you
can choose where to send your query results.

> To choose a query destination


1 From the Query Designer toolbar, choose Query Destination.
2 In the Query Destination dialog box, choose an output destination, and fill out any
additional fields as required.

Choosing a query destination


* Query Destination

Choose an output destination to


direct the results of your query
using these buttons.

Use this table to choose the destination for your query output.
If you want to Choose this output option
Display the results of your query in a Browse window Browse
Save the results of your query in a temporary read-only Cursor
table with the name you assign it
Save the results of your query as a table with the name Table
you assign it
Make the query results available for use with Graph
Microsoft Graph, a separate application included
with Visual FoxPro
Display the results of your query in the main Visual Screen
FoxPro window, or in the currently active output window
Send the output to a report file (.FRX) Report
Sends the output to a label file (.LBX) Label

Many of the options have additional choices you can make to affect the results. For
example, the Report option lets you open a report file and customize the report before
printing, or you can choose a Report Wizard to help you create the report. For more
information, see Chapter 7, “Designing Reports and Labels.”

66 User’s Guide
Chapter 4 Retrieving Data

Verifying Your Query


If you want to make sure the query is properly defined, you can view the SQL
statement built by the Query Designer. Also, you can add comments to the query
describing its purpose. The comments you add appear in the SQL window.

Viewing Your SQL Statement


At any time while you are creating your query, you can see the SQL statement your
query is building by choosing View SQL from the Query menu or by choosing the
SQL button on the toolbar.
A read-only window displays the SQL statement. You can copy the text in the window
and paste it into the Command window or incorporate it into a program.

> To see the SQL statement for your query


¢ Inthe Query Designer toolbar, choose the SQL button.

The SQL statement for a query

m query1_qpr [Read Only]


} SELECT Orders.cust_id, SUM(Orders.order
net) ;7)
| FROM testdata!orders; _—
GROUP BY Orders.cust_id;
HAVING SUM(Orders.order_net)>S50000

Choose the SQL button to see the


SQL statement for a query.

Adding a Comment to Your Query


If you want to identify your query in some manner, or add notes about it, you can add
comments to your query that will help identify it and its purpose.

> To add a comment to a query


1 From the Query menu, choose Comments.
2 Inthe Comment box, type any notes you want to make about the query.
3 Choose OK.

User’s Guide 67
Part 2 Finding Information

Adding comments to your query

j pent, yD)
This query finds customers with net orders
_ {greater than $ 50.000.

Comments you enter appear at the top of the SQL window, preceded by an asterisk.

Customizing Queries
Other options available with the Query Designer make it easy to further customize
your queries. You can use filters to expand or narrow your search. You can also add
expressions to perform calculations or functions on the data in your fields.

Fine-Tuning Your Search


You might find that you want more control over the results returned by a query. For
example, you might want to find records which meet more than one criterion, such as
customers from a given state who have outstanding balances greater than $1000. Or,
you might need to retrieve records which meet either one criterion or another:
customers from Washington or from California. In either case, you need to add more
statements to the Filter tab.
In Visual FoxPro, filter statements are automatically combined with a logical AND
when you enter them in successive rows in the Filter tab. If you want to retrieve
records which meet two or more alternative conditions, you can insert a logical OR
operator between rows with the Add Or button.

Narrowing Your Search


If you want your query to retrieve only records that meet more than one criterion, list
the criteria on separate lines in the Filter tab. Criteria in a series are combined with an
implicit AND statement, so that only records which meet all the criteria listed will be
retrieved.

For example, suppose you are searching an employee table, and you want to see all
the Sales Representatives in the United Kingdom. You would enter the two conditions
you are searching for on separate lines:

68 User’s Guide
Chapter 4 Retrieving Data

Combining two filters


susiseciinnas

Employee. title i Sales Representative


Employee. country fod i 7 £ None>| |

When you combine filters on adjacent lines with AND conditions...


..the query retrieves employees who are Sales Representatives in the UK.

> To set AND conditions


¢ Enter filters in the Filter tab, and choose AND in the Logical column.

Expanding Your Search


If you want your query to retrieve records which meet any of a series of filters,
combine filters by inserting OR conditions between them.
For example, you might want to search for customers who live in Washington or
California:

Adding an OR between two filters


YUE.

Field Nam Losical


Customer.region Like ; OR
Customer.region | Like CA, |

When you combine two filters with OR...


..the query retrieves records that meet either condition.

re “Walla Walla
a F 4

eattle

User’s Guide 69
Part 2 Finding Information

> To set OR conditions


° Select a filter, and then choose OR in the Logical column.

Combining Conditions
You can also combine AND and OR conditions to select specific sets of records.
For example, you might want to retrieve records for customers from Washington or
California who have maximum order amounts larger than $5,000.

Combining different filters

Customer.region
Customer.maxordamt
Customer.region
Customer.maxordamt <None>

When you connect filters with a combination of conditions...


..the query retrieves records that meet the combined condition.

ountry Store

Trail's Head Gourmet Provisioners

Eliminating Duplicate Records from a Query


Duplicate records are records in which every field of the result matches. If you want
to remove duplicate records from the query results, select the No Duplicates box on
the Miscellaneous tab. Otherwise, make sure the No Duplicates box is cleared.
Note If No Duplicates is selected, the word DISTINCT precedes the fields in the SELECT
portion of the SELECT command.

Retrieving a Number or Percentage of Top Records


You can specify how many or what percentage of records with the highest or lowest
values in a particular field you want the query to return. For example, the query can
display those records with the 10 highest or lowest values in a specific field or the
records with the highest or lowest 10 percent of values in the field.

70 User’s Guide
Chapter 4 Retrieving Data

Using the Top setting on the Miscellaneous tab, you can either set a number or a
percentage of records you want to see. To set whether you are choosing the top or
bottom, you set the sort order for your query to either descending to see the top or
ascending to see the bottom.

> To retrieve a number or percentage of top records


1 Inthe Order By tab, select the field you want to retrieve top values for, then
choose Descending to display the highest values or Ascending to display the
lowest values. If you are sorting on additional fields, place them after the top
values field in the order by list.
2 Inthe Miscellaneous tab, type the number for the percentage or the number of
highest or lowest values you want retrieved in the Number of records box. To
display a percentage, choose Percent.
3 If you do not want duplicate records included in the number or percentage, choose
No duplicates.

Adding Expressions to a Query


You can create more flexible and powerful queries if you incorporate expressions,
either in a filter or as result fields.

Adding Expressions to Results


You can also include functions and expressions in the output of your query, using the
box at the bottom of the Fields tab. If you want to name the field holding the
expression, you can add an alias.
For example, you might want your query results to include the sum of all order
amounts with the alias Total:
SUM(orders.order_amt)AS Total

Creating an expression to include in your query results

Click the dialog button to


open the Expression
Builder dialog box.
Use this box to create an expression
to include in your query.

User’s Guide 71
Part 2 Finding Information

You can type an expression directly into the box or use the Expression Builder on the
Fields tab.

> To add an expression to your query output


1 In the Fields tab, type the expression in the Functions and Expressions box.
YOre
Choose the dialog button to use the Expression Builder and enter an expression in
the Functions and expressions box.
2 Choose the Add button to place the expression in the Selected fields box.

Note Null values are ignored in calculations. For more information on null values in
expressions, search for “Null Values” in Help.

Filtering with Expressions


Instead of simply searching for records that match one or more fields, you can use an
expression to combine two fields, or perform a calculation based on a field and search
for records that match the combined or calculated field.

You can type expressions directly into the Example box. If you want some help, you
can use the Expression Builder, which is available from the dialog button next to the
Expressions and Functions box in the Fields tab.

For example, using the Orders table, you might want to check total discounts for a
customer by combining order amount and order discount in an expression like the
following:
Orders.order_amt * Orders.order_dsc

Creating an expression in the Expression Builder

This expression
multiplies the values
of two fields.

_ {ship_count
ship_via
A_|marain
| padvance
4_Pageno
= SK yy x / |_pbpage

eps [Orders j *| freee

72 User’s Guide
CHAPTER 5

Updating Data with Views

To extract a set of records from a table, make changes to those records, and send the
updates to the source tables, you can use a view. You can create views from local
tables, from other views, from tables stored on a server, or from remote data sources,
such as Microsofte SQL Server™, via ODBC. You can even have Visual FoxPro send
updates to the source table when you update or change the set of records in the view.
This chapter covers creating simple, single-table local and remote views. For
information about creating complex views and combining local and remote data in a
single view, see Chapter 6, “Querying and Updating Multiple Tables.”
This chapter discusses:
¢ Creating Views
¢ Connecting to Remote Data
¢ Updating Data
¢ Customizing Views

Creating Views
Creating queries and views are similar processes. The main difference is that views
can be updatable, while queries are not. Use queries when you want to display a set of
records that are read-only. Queries are a SQL - SELECT statement saved as text in a
.QPR file; use views when you want to extract an updatable set of data from local or
remote tables.

User's Guide 73
Part 2 Finding Information

Queries, views, and remote views

Table

Query

View

Server

Updates

For example, you can display, but not update, the records retrieved by a query. But
when you edit the records in a view, you can have the changes sent to the source table,
updating it.

Views are a feature of Visual FoxPro databases. You can only use views when their
parent database is open.

Using a View Wizard


You can create local and remote views with a view wizard. To set up an updatable
view using tables on an ODBC data source, use the Remote View Wizard.

> To create a view with a wizard


1 In the Project Manager, select a database.
2 Select Local Views or Remote Views, and choose New.
3 Choose View Wizard.
4 Follow the instructions on the wizard screens.

74 User’s Guide
Chapter 5 Updating Data with Views

Starting the View Designer


To create a view of a local table, use the View Designer. Local tables can include
native Visual FoxPro tables, any tables in a .DBF format, and tables stored on local
servers.
To use the View Designer, first create or open a database. When you expand the plus
sign next to the name of a database in the Project Manager, the Data tab shows you the
components of the database.

Local views are stored in the database.

ba Project Man Jer Projl ee

EB Databases
FH @ testdata
ith Tables
ocal Views
>» @ Remote Views
> Connections
fF} Stored Procedures
i Free Tables
‘ Queries
¥) j=) Documents

> To create a local view


1 From the Project Manager, select a database.
2 Click the plus sign next to the Databases symbol.
3 Under Databases, select Local Views and choose New.
4 Choose New View.
5 In the Add Table or View dialog box, select the table or view you want to use,
then choose Add.
6 After choosing the tables you want in your view, choose Close.
The View Designer appears, showing the table or view you selected.
7 In the Fields tab, select the fields you want to see in your view results.
8 To view the results of your view, choose the Run button.

You can also start a view by choosing New from the File menu and choosing View.

User’s Guide 75
Part 2 Finding Information

View Designer for a local view


oe View Designer - Vit wl

View Designer 5 Ez

eng_name
no_in_unit

Products. prod_name
Products.eng_name
Products.no_in_unit
Products. uni

Using the View Designer is essentially the same as using the Query Designer.
However, the View Designer has an extra tab—the Update Criteria tab—where you
can control how updates are made. For more information about using the Update
Criteria tab, see “Updating Data” later in this chapter. For more information about
using the Query Designer, see Chapter 4, “Querying Data.”

Connecting to Remote Data


With remote views, you can extract a subset of the data on a remote ODBC server
without having to download all the records to your local computer. You can work on
the selected records locally, then send the changes or additions you make back to the
remote data source.
You can connect to a remote data source in one of two ways. You can directly access
any ODBC data sources registered on your computer or you can design custom
connection using the Connection Designer.

ODBC is installed on your system when you choose the Complete or Custom
installation option of Visual FoxPro. For more information about registering ODBC
data sources, see Chapter 1, “Installing Visual FoxPro,” in the Installation Guide and
Master Index.

76 User’s Guide
Chapter 5 Updating Data with Views

Creating a Connection
If you want to create a customized connection for a server, use the Connection
Designer to create or customize a connection. The connections you create are saved as
part of the database and contain information about how to access a specific data
source.

Connection Designer
onnection Designer - Conn
OEE ee WG

You can set connection options to save and name the connection for future use. You
might have to consult your system administrator or server documentation to find the
right settings for connecting to your particular server. Connection Designer settings
are described in more detail in Chapter 8, “Creating Views,” in the Developer’s Guide.
Note Before you can create a connection, you must have a database open.

> To create a new connection

1 In the Project Manager, select a database.


2 Select Connections and choose New.
3 In the Connection Designer, enter the options that correspond to your server
requirements.
4 From the File menu, choose Save.
In the Save dialog box, enter a name for the connection in the Connection Name
box.
6 Choose OK.

User’s Guide 77
Part 2 Finding Information

You can also create a connection by choosing New from the File menu and selecting
the Connection option.

Creating a New Remote View


To gain access to your remote data in a view, you can use an existing connection or
create a connection to use with your new view.

> To create a new remote view


1 Inthe Project Manager, select Remote Views and choose New.
2 Choose New View.
3 In the Select Connection or Data Source dialog box, select the Available data
sources option.
_Or-
If you have previously defined and saved a connection, select the Connections
option.
4 Select a data source or connection and choose OK.
If required, in the Microsoft SQL Server or other login dialog box, enter your login
ID and password.

You can also choose New from the File menu and select the Remote View option.
Once the connection is established, the Open dialog box appears so you can select a
table on the remote server.

Tables on a remote server

Select a table once you have


connected to a server.

After you select a table, the View Designer appears.

78 User’s Guide
Chapter 5 Updating Data with Views

View Designer for a remote view

uthors.au_lIname
uthors.au_fname
uthors.telephone
uthors.address
uthors. city

Table selected from a remote data source.

To continue creating your remote view, you can select output fields and set filters just
as you would a local view.

Updating Data
You can use either local or remote views to update your tables.

Sending Updates to Tables


In the View Designer, the Update Criteria tab allows you to control how the changes
you make to remote data (updates, deletes, and inserts) are sent back to the remote
data source. You can also enable and disable updating for specific fields in the tables
and set the SQL update method appropriate to your server.

Making a Table Updatable


If you want to have the changes you make to the local version of a table sent back to
the source table, you need to set the Send SQL Updates option. You must set at least
one key field to use this option. If the table you select has a primary key field defined
and you have selected it in the Fields tab, the View Designer automatically uses the
primary key field for the table as a key field for the view.

> To enable updating of source tables


¢ In the Update Criteria tab, set the Send SQL updates option.

User’s Guide 79
Part 2 Finding Information

Setting Key Fields


When you first open a table in the View Designer, the Update Criteria tab shows
which fields in the table are defined as key fields. Visual FoxPro uses key fields to
uniquely identify the update records in remote tables that you have modified locally.

> To set a key field


¢ In the Update Criteria tab, click the key column next to the name of the field.

Setting key fields in the Update Criteria tab


Click here to set a key field.

indexid
¥ group
¥ indent
| ov stext
J, y| fiternid

If you have changed the key fields and want to restore them to the original setting in
the source table, choose Reset Key. Visual FoxPro will check the remote tables and
use the key fields from those tables.

Updating Specific Fields


You can specify that only certain fields in any given table be updatable. You must
have a key field defined for a table in order to make any fields in that table updatable.
If fields are not marked as updatable, users can make changes to the field in a form or
Browse window, but these changes are not sent to the remote table.

> To make a field updatable


¢ In the Update Criteria tab, click the updatable (“pencil”) column next to the name
of the field.

80 User’s Guide
Chapter 5 Updating Data with Views

Making a field updatable in the Update Criteria tab


POLO
: \“\“

group
indent
text

Click here to make a field updatable.

Updating All Fields


If you want to be able to make changes to all the fields in a table, you can set all the
fields in a table as updatable.

> To make all fields updatable


¢ Inthe Update Criteria tab, choose Update All.

Note You must have a key field defined in a table in order to use Update All. Key fields are not
affected by Update All.

Controlling How Update Conflicts are Detected


If you are working in a multiuser environment and using data accessible to others on a
server, it is possible that others are attempting to make changes to the records on the
remote server at the same time you are. To have Visual FoxPro check if data you are
working with in a view has been changed by another user before you attempt to
update it, use the options in the Update Criteria tab.
The options in the SQL WHERE Clause Includes box in the Update Criteria tab help
you manage how records will be updated when multiple users might be accessing the
same data. Before an update is allowed, Visual FoxPro checks specified fields in the
remote data source table to see if they have changed since the record was retrieved
into the view. If the records in the data source have changed, the update is not
allowed.

Setting the SQL WHERE clause in the Update Criteria tab

User’s Guide 81
Part 2 Finding Information

These options determine which fields are included in the WHERE clause in the
UPDATE or DELETE statement that Visual FoxPro sends to the remote data source or
source table when you make changes to or delete records in the view. The WHERE
clause serves to check if the data on the server has changed since you retrieved the
record for use in your view.
To Choose this SQL WHERE option
Have the update fail if a key field has been Key fields only
changed in the source table
Have the update fail if any of the fields marked as Key and updatable fields
updatable have been changed on the remote table
Have the update fail if any fields you change Key and modified fields
locally have been changed on the source table
Have the update fail if the timestamp of the Key and timestamp
record on the remote table has changed since you
first retrieved it (only available if the remote table.
has a timestamp column)

For more information about detecting and resolving update conflicts, see Chapter 17,
“Programming for Shared Access,” in the Developer’s Guide.

Customizing Views
You can customize views by defining how a field in a view displays, by controlling
field display and data entry, by using expressions in views, by setting views up to
prompt for values, and by setting advanced options to fine tune how data is exchanged
with a server.

Controlling Field Display and Data Entry


Because your view is part of a database, you can take advantage of some of the same
properties that a database provides for fields in a table. For example, you can assign
captions, enter comments, or set validation rules to control data entry.

> To control field display and data entry


1 Create or modify a view in the View Designer.
2 In the Fields tab, select a field in the Selected fields list.
3 Choose Properties.

82 User’s Guide
Chapter 5 Updating Data with Views

View Field Properties dialog box

Yi,

4 In the View Field Properties dialog box, enter validation, display, and field type
settings.

For more information about field validation, display, and mapping, see Chapter 7,
“Working with Tables,” in the Developer's Guide.

Controlling the Update Method


To control how information in key fields is actually updated on the server, use the
options in the Update Using option group. These options determine what SOL
command is used in the update statement sent to the server or source tables when key
fields in records are updated.

Update settings in the Update Criteria tab

You can specify that records be deleted and then replaced with the new values entered
in the view (SQL DELETE then INSERT), or that server records be changed via the
SQL UPDATE function supported by the server.

Adding Expressions to Remote Views


As with queries, you can include functions and expressions as filters in views.

> To add an expression to a view


¢ In the Filter tab, select Expression from the Field Name box.

User’s Guide 83
Part 2 Finding Information

If you are basing a view on a remote data source, the functions shown in the
Expression Builder reflect the functions supported by that server. Check your server
documentation for a listing of the functions your server supports. Visual FoxPro does
not attempt to parse the expressions you build; instead, it passes them on to the remote
server.

Prompting for Parameters


You can set up views that prompt for the entry of a value to complete the query. For
example, suppose you want to create a query to find customers located in a specific
country. To do this, you need to define a filter on the country field and specify a
parameter as the example in the filter. Parameter names can be any combination of
alphabetic characters, numbers, and single quotes.

> To set up a parameter for a view


1 Inthe View Designer, add a new filter or select an existing filter in the Filter tab.
2 Inthe Example box, type a question mark (?) and the name of the parameter.
Parameter value entered as part of a filter for a view
Veete

When you use the view, a message box appears prompting for a value to include in the
filter.

Setting Timeout Intervals


If you need to adjust how Visual FoxPro interacts with your server, you can set timing
options.

> To set timeout intervals


1 In the Project Manager, select a connection and choose Modify.
2 Inthe Timeout intervals area, set the options you need.
3 From the File menu, choose Save.

For more information on setting timing options, search for “Connection Designer” in
Help.

84 User’s Guide
Chapter 5 Updating Data with Views

Optimizing Performance
You can optimize your views by setting data fetching and performance options. Use
the Advanced Options dialog box to fine tune how records are retrieved in a view or
how updates are made to the server or source tables.

Advanced Options dialog box


Advanced Options
He AX

> To set advanced options


1 From the Query menu, choose Advanced Options.
2 Inthe Advanced Options dialog box, set the connection information and data
fetching options you need.
3 Choose OK.

For more information, search for “Advanced Options dialog box” in Help. For more
information about optimizing your views, see Chapter 8, “Creating Views,” in the
Developer's Guide.

User’s Guide 85
_ Paead ihngon Hem rong
he pA 4458 4 By ea ra. W peep’ rea weet ue
Spica! » Pies ; MN) ag
Me . chninetal ma Anis: eee en aiidalah guitans hare ee a
j :
da ie
’ . aici auc 3 ARSE ae Ratire yee mel dias Pelpep
is aah” meesne stan
eee ‘Sri TO eoryge SH oh Soe Leta wae
i.
ae Ors ey eee
i} Promptin: it) ™ i

: 2 ee Bee | be Vv Nest 6 fey ity ery

roe. eee hx iar 4 iyuery


Seow Fy vu ¥ Ari ying efile

ir Gtas eh ee iy Pala bene Hie, Par tet


wh pdnadbee« ) ihacw on wwe > werk Tae

i a ‘ Se

> jo oe Oy 2 pers ors oe

’ ; ew iy , awr a a Psu or whew

bit Ry Retaple tee: mh seemslcns Seasteglt


Cm ina eg S- erermpate « a ey ase

See Tyeeoc as
pink bow paper viTeak |
Mii a a ee ee
titer.

Setting Teeaa
acon Sigg
nai Minas +4"FeltHen
Pe
eee
oe
} Uf e136 ee Se ra Aptos Punnett Peonyvont geen i.
i ata -

© Wee teary Sy
1 Pel Ravage
008s
, 4 nite +e yea hint, . ~~
Ps oy nF eet 3 Tee agit, )\ = fiw Ost ate :

9 De ay Hie lend cli ar

i eo ae
>
Querying and Updating Multiple
Tables

With Visual FoxPro, you can query multiple tables and views, and combine remote
and local data into a view. This capability is useful when the data you need is stored in
two or more tables, or split between local tables and tables on a remote data source.
For information about setting up simple one-table queries and views, see Chapter 4,
“Retrieving Data,” and Chapter 5, “Updating Data with Views.” For more information
about joins, see Chapter 7, “Working with Tables,” in the Developer ’s Guide.
This chapter discusses:
* Querying Multiple Tables and Views
¢ Using Multiple Tables in Views
¢ Using Multiple Remote Tables in a View
¢ Combining Local and Remote Data in a View

Querying Multiple Tables and Views


When you need access to information stored in two or more tables, just add all the
relevant tables to your query and join them on common fields. Then you can search
the records in all the tables for the information you need. You can use any
combination of database tables, free tables, and local or remote views in your queries.

User's Guide 87
Part 2 Finding Information

Using multiple tables or views in a query

Free Table Database Table

Local View
cust_id | i pe i
: compan! oe {|company : call -
Bnet | contact eae Remote View
title | to_name
to_addre:

Remote_customer.city
Remote_customer.region
Remote_customer.postal
Remote_customer.country

Because the term “view” can refer to both an input source or the object you are
creating, the term “table” is used for both tables and views used as input sources. The
term “view” is used for the object you create with the View Designer.

Adding Views and Tables to a Query


When you add tables or views to your query, Visual FoxPro suggests a possible join
between the tables or views, based on matching field names.
For example, if you add the Customer table in SAMPLES\DATA to the Query
Designer, and then add the Orders table, Visual FoxPro suggests a join between the
tables based on the matching fields Customer.cust_id and Orders.cust_id.

88 User's Guide
Chapter 6 Querying and Updating Multiple Tables

Suggested join between tables


Query Designer z Query1 0

Visual FoxPro creates


a join .baseda on oo py
ba
cus
matching fields. ——==> emp_id
to_name
to_address

Customer.company
Customer.contact
Customer. title
Customer. address
Customer. cit
<

If you are using a database that contains persistent relationships defined between the
views or tables within it, Visual FoxPro uses the existing relationships as default joins.
If you want to add database tables or views to your query, you may need to open the
appropriate database to make them available.

> To add a table or view to a query


1 Inthe Query Designer toolbar, choose Add Table.
2 Inthe Add Table or View dialog box, select the database you want to use, choose
Tables or Views, select the table or view you want to add, and choose OK.
Lore
If you want to add a table that is not part of the database, choose Other, locate the
table in the Open dialog box, and choose OK.
3 Inthe Join Condition dialog box, verify the suggested join.
If Visual FoxPro cannot suggest a likely match between fields, select the matching
fields in the Join Condition dialog box yourself.
4 Choose OK.

Controlling Record Selection with Joins


With multiple tables in your query, you can control which records your query selects
by altering or adding joins. Using the Join Condition dialog box, you can change the
join type set between the tables.
Joins appear automatically when you add the tables; however, if the field names of
related fields do not match, you might have to create your own joins between tables.

User's Guide 89
Part 2 Finding Information

You can create additional joins by dragging between the fields of tables in the Query
Designer, or by choosing the Add Join button in the Query Designer toolbar to display
the Join Condition dialog box.

Join Condition dialog box

When you add or alter a join, you can select a type of join to expand or narrow your
results. The easiest way to create a join is by using the Join Condition dialog box.

> To create a join between tables


1 Add two or more tables to a query.
2 Inthe Query Designer toolbar, choose Add Join.
3 Inthe Join Condition dialog box, select the related field names in the two tables.
Note Join columns only if they have the same size and data type.
4 Select a join type:
To retrieve Use
Only records from both tables that match the Inner Join
join criteria, the most common type ofjoin
All records from the table on the left side of the Left Join
join criteria and only records that match the
join criteria from the table on the right side of
the join criteria

To retrieve Use

All records from the table on the right side of Right Join
the join criteria and only records that match the
join criteria from the table on the left side of the
join criteria
All records from both tables whether or not Full Join
they match the join criteria

5 Choose OK.

90 User's Guide
Chapter 6 Querying and Updating Multiple Tables

For more information about joins, see Chapter 8, “Creating Views,” in the Developer's
Guide.

You can also delete or modify existing joins. Although you can still run a query
without the joins, the results usually have little practical value and may require large
amounts of time to process.

> To delete a join


* Select the join line in the Query Designer and choose Remove Join Condition
from the Query menu.
ata
In the Join tab, select the join condition and choose Remove.

Besides filters and join types, you can control your results by changing the criteria
used in the join. Joins do not have to be based on an exact match of fields; you can set
up different join relationships based on Like, Exactly Like, More Than, or Less Than
criteria.
Join criteria are similar to filter criteria; they both compare values and then include
records that match the criteria. Unlike a filter which compares a field value to a filter
value, the join criteria compares the field value from one table to the field value of the
other table.
For example, when you query two tables joined on their respective customer ID fields
(Customer.cust_id = Orders.cust_id), the query retrieves only the records in which
these two fields match, and which also meet any other filter you set in the query.

> To modify a join


1 Inthe Join tab, select the join you want to modify.
2 Change the join conditions as needed.

For more information about logical operators used in join criteria, search for “Logical
Operators” in Help.

Using Multiple Tables in Views


You can also combine two or more local tables in a local view. The process of
defining a multi-table view is similar to working with multiple tables in a query. But
using views gives you the added capability to update the source tables when working
with the output of the view.
For example, you can join the Customer and Orders tables from SAMPLES\DATA in
a view, and set criteria to select a subset of the combined records. As you update the
results in a Browse window or in a form, the updates you make can be sent back to
update the source tables.

User's Guide 91
Part 2 Finding Information

Combining tables in a view


<<, View Designer -.View11
View Designer

cust_id
| company
contact
title

Customer.company
Customer.contact
Customer. title
Customer. address
Customer. city
Customer.region

Updates are sent to the source tables.

> To join tables in a view


1 Add a table in the View Designer.
2 Choose Add Join, change the join conditions if you wish, and choose OK.

> To enable updating of the source tables


1 In the View Designer, select the Update Criteria tab.
2 Select Send SQL updates.

Note To activate the Send SQL updates option you must first set a key field in one of the
tables.

For more information about controlling updates to tables, see Chapter 17,
“Programming for Shared Access,” in the Developer's Guide.

Using Multiple Remote Tables in a View


When you connect to a remote data source, you can gain access to many related
tables. You can select the tables you need and adjust the relationships between them, if
necessary, to get the information you need.
For example, suppose you are connected to a publications database, which contains
many interrelated tables. If you are searching for information about titles and authors,
you could use three related tables: Authors, Titles, and Titleauthor.

92 User's Guide
Chapter 6 Querying and Updating Multiple Tables

Multiple tables in a remote view

‘Authors. au_fname
Authors.telephone

Three linked tables from a remote data source.

> To create a multi-table remote view


From the File menu, choose New, select Remote View, and choose New File.
2 In the Select Connection or Datasource dialog box, select a predefined
connection or an available data source.
If required, log on to the server.
In the Open dialog box, select the tables you want to use.
In the Join Condition dialog box, accept the default join, or set up a join as
needed.

As with local views, you can use the options in the Update Criteria tab in the View
Designer to control how updates are made to the source tables.

Combining Local and Remote Data in a


View
If data you need is stored on a remote data source, and is related to information in a
local table, you can combine the local and remote data in a view.
First, you can create a remote view to select only the relevant records you want to
work with from the remote server; then, using a local view, you can join the remote
view with the related local table.

User's Guide 93
Part 2 Finding Information

For example, suppose you have a large master customer database on a server and a
local table that stores country code information. You can create a remote view,
connect to the server, and select customer records of interest; then create a local view
and add the remote view and the local table to it.

As you work with the records in the local view to enter new orders, you can choose to
update the remote view and the local table. If you close the local view and then close
the remote view, the remote view will update the table on the remote customer
database.

Remote view and local table in a local view

Orders.eust_id
Orders.emp_id
Orders. to_name
| Orders.to_address
Orders.to_city
Orders. to_region

Remote customer table from SQL Server Linke to local orders table.

> To combine remote and local data in a view


Create a remote view and add one or more tables from the remote server.
Create a new local view and add the remote view you just created to it.
Add the related local table to the view and join them on a common field.
Set a filter in the local view and run it.
Update the view results to update both the local table and the remote view.
DB

fF
oo
ao
— Close the local view and then the remote view to update the data on the remote
server.

For more information about working with views within other views, see “Combining
Views” in Chapter 8, “Creating Views,” in the Developer’s Guide.

94 User's Guide
pe a a
PART 3

Displaying Information

When you want to effectively communicate the information in your


tables and databases, you need to print it or present it in a usable
form. Visual FoxPro reports and labels make it easy to print the
contents of tables and the results of queries, while forms provide a
convenient way to view and edit your data.

Chapter 7 Designing Reports and Labels


When you want maximum flexibility in formatting, printing, and
summarizing your data, use the Visual FoxPro Report Designer. If
mailing labels or other types of labels are what you need, you can
create them with the Label Designer.

Chapter 8 Managing Data Through Forms


If your projects require a great deal of data entry, or if you want to
present information in an easy-to-use format, the Form Designer
helps you set up clear, usable forms in a standard or customized
format.

User's Guide 95
enin gi se:
(helene iMy

uo

rie

a
any
ys ‘
CHAPTER 7

Designing Reports and Labels

Reports and labels provide a flexible way for you to display and summarize your data
in a printed document. Reports have two basic components: a data source and a
layout. The data source is often a set of tables in your database but it can also be a
view, a query, or a cursor. Views and queries filter, order, and group data from the
database and the report layout defines the printed format of the reports. After you
have a table and a view or query defined, you are ready to create reports or labels.
This chapter discusses:

Planning Your Report Layout


Creating a Report Layout
Creating a Mailing Label Layout
Modifying Your Layout
Adding Report Controls
Grouping Data on Your Layout
Customizing Your Layout
Previewing and Printing Your Report or Label

Planning Your Report Layout


You can design your report to display your data in a variety of ways on the printed
page. Using the Report Designer or report wizards, you can design comprehensive
lists, summaries, or special subsets of data like an invoice. Designing a report has four
main steps:
1. Determining what type of report to create.
2. Creating the report layout file.
3. Modifying and customizing the layout file.
4, Previewing and printing the report.

User's Guide 97
Part 3 Displaying Information

The report creation process

Decide the
general layout

Ey Report Designer - Repor


Q : YW y

sport Design
NS

y oa gor

Lees: : = Sf:
contact. = pas od cae

Start the mares a


layout 5
|) (DATE ()__
Ee mee
the report

Customize the
layout

Determining the General Layout


Before creating a report, decide the general format you want your report to have. Your
report might be as simple as a telephone list based on a single table or as complex as
an invoice based on multiple tables. You can also create special types of reports. For
example, a mailing label is a special report with a layout designed to fit a special type
of paper.

98 User's Guide
Chapter 7 Designing Reports and Labels

General report layouts

e 7 ae
a
ES
SSAA
SRE

ee
wai oO

co

A
OSES
SOIC
ARERR
Seem a
eae
aiaeaamareocnneee
meNESRRRERHEE
ANAT
SRR
a
ETERS

Column report Row report One-to-many Multi-column Label


report report

To help you choose a layout, here are some descriptions of general layouts, their
common uses, and examples.
Layout Type Description Examples
Column One record per row with fields placed Group/Total report
horizontally across the page Financial reports
Inventory
Sales summary
Row One column of records with fields placed Lists
vertically down the side
One-to-many' One record or one-to-many relationship Invoices
Account statements
Multi-column More than one column of records with Telephone directory
fields placed vertically down the left Business cards
margin
Label More than one column of records with Mailing labels’
fields placed vertically down the left Name tags
margin; printed on special paper

1 Layouts that have an associated report wizard

After you select the general report layout that meets your needs, you can create the
report layout file with the Report Designer.

Understanding Report Layout Files


A report layout file, which has an .FRX file extension, stores the specifications for the
report. Each report file also has an associated file with an .FRT file extension. The
report file specifies the fields you want, the text to print, and the placement of the
information on a page. To get the information from your database to the printed page,
you process it by printing the report file. The file does not store the values for each of
the data fields, only placement and format information for that particular report. The
values can change each time you run the report, depending on the changes that have
occurred in the fields of the data source used by the report file.

User's Guide 99
Part 3 Displaying Information

Creating a Report Layout


You can create report layouts three ways in Visual FoxPro:
* Create simple single or multiple table reports with a Report Wizard.
* Create a simple report from a single table with Quick Report.
* Modify existing reports or create your own report with the Report Designer.

With each of these methods, you create a report layout file you can modify using the
Report Designer. The Report Wizard is the easiest way to start a report and
automatically offers many of the Report Designer’s customization features. The Quick
Report is the fastest way to create a simple layout. If you create a report directly in the
Report Designer, the Report Designer presents you with a blank layout.

Using a Report Wizard


Whenever you want to create a report, you can use a report wizard to help you set it
up. The wizard asks you a series of questions and creates a report layout for you based
on your answers.
Visual FoxPro provides these report and label layout wizards:
¢ Report
¢ Group/Total
¢ One-to-Many
¢ Label
¢ Mail Merge

The wizard you choose depends on the general layout and complexity of your report.

> To use a report wizard


1 In the Project Manager, select Reports.
2 Choose New.
3 Choose Report Wizard.
4 Select the type of report you want to create.
5 Follow the instructions on the wizard screens.

You can also access the report wizards from the menu by choosing Wizards from the
Tools menu, and selecting Report.
Once you use a wizard, you can use the Report Designer to add controls and
customize your report. For more information, see “Customizing Your Layout” later in
this chapter.

100 User's Guide


Chapter 7 Designing Reports and Labels

Starting the Report Designer


If you do not want to use a report wizard, you can begin with a blank report layout
and add controls yourself.

> To create a blank report


1 In the Project Manager, select Reports.
2 Choose New.
3 Choose New Report.
The Report Designer appears.

You can use any of the Report Designer features to add controls and customize your
report.

Creating a Mailing Label Layout


A label is a multi-column report layout that has special column settings which match a
particular label paper. In Visual FoxPro, you can create labels quickly with the Label
Wizard or the Label Designer.

Using the Label Wizard


The Label Wizard is an easy method for creating labels. Once you create the label file
with the wizard, you can use the Report Designer to customize it.

> To create labels with the Label Wizard


1 In the Project Manager, select Labels.
2 Choose New.
3 Choose Label Wizard.
4 Follow the instructions on the wizard screens.

You can use the label layout as it is or customize it using any of the features described
for reports.

Starting the Label Designer


If you do not want to use the wizard to create your labels, you can create a layout with
the Label Designer. The Label Designer is like the Report Designer and uses the same
menus and toolbars. The two designers are different in the default page and paper they
use. The Report Designer uses a full page of standard paper. The Label Designer set
its default page and paper to match standard label paper.

User's Guide 101


Part 3 Displaying Information

> To create a label with the Label Designer


1 In the Project Manager, select Labels.
2 Choose New.
3 Choose New Label to display the New Label dialog box.

Standard label paper choices appear in the New Label dialog box

15/716 Chm Ware


15/16" 3-172"
i-7716" 4"
2-7716" 3-172"
2-15716" 4"
3-172"

4 From the New Label dialog box, select a label layout and choose OK.
The Label Designer displays a page definition for the label layout you selected.

You can specify a data source and insert controls just as you would for a report. For
more information, see “Customizing Your Layout” later in this chapter.

Modifying Your Layout


If you have a blank report or label, or the wizard or Quick Report generates a report
that does not quite fit your needs, you can modify it in the Report Designer.
In the bands of the Report Designer, you can insert a variety of controls that hold the
labels, fields, variables, and expressions that you want in the printed report. For
example, in a phone list layout, you would place the field controls for the names and
phone numbers as well as label controls and column headings at the top of the list. To
enhance your report’s visual appeal and readability, you can add line, rectangle, and
rounded rectangle controls. You can also include picture controls. Each of these
controls are shown in the figure below.

102 User's Guide


Chapter 7 Designing Reports and Labels

Report layout file and the resulting report

|yw List of Contacts

ore FISSA Fabrica (91) 598 9444

You can open your report or label in the Report Designer to modify and customize the
layout.

> To modify a generated report or label


1 In the Project Manager, select a report or label.
2 Choose Modify.

You use the bands of the report to determine what each page, group, and the beginning
and end of your report looks like. Report bands can be resized. In the report bands,
you add report controls, then move, copy, resize, align, and adjust them to arrange the
text and fields in your report.

Planning Data Placement


Once you have a report layout, you can modify the placement of the data on the report
page. Using the bands in the Report Designer, you can control where data is printed
on the page. Your report layout can have several bands. The figure below shows some
of the bands a report can include and typical contents for each band. Notice that the
bar below each band identifies the band.

User's Guide 103


Part 3 Displaying Information

Report bands in the Report Designer

Place controls for title, date, page


number, or company logo, and box Place date, page number
around the title contents here. and column headings here.

€]' Report Designer - Report! i fi ma Z : ene . i ] FS

Place grouping field


and separation
line here.

Place date, page


number, subtotal line,
subtotals and
descriptive text here.

Place data and descriptive Place “grand totals” Place group totals and
text here. text here. “subtotal” text here.

A report can also have multiple group bands or bands for a column header and footer.
You can add these bands using the procedures in “Defining the Report Page” and
“Grouping Data on Your Layout” later in this chapter. You can use the table below to
determine which bands you want to use.
Use this band To print Use this command
Title Once per report Choose Title/Summary from the Report menu.
Page header Once per page Available by default.
Column header Once per column Choose Page Setup from the File menu and set Column
Number greater than 1.
Group header Once per group Choose Data Grouping from the Report menu.
Detail band Once per record Available by default.
Group footer Once per group Choose Data Grouping from the Report menu.
Column footer Once per column Choose Page Setup from the File menu and set Column
Number greater than 1.
Page footer Once per page Available by default.
Summary Once per report Choose Title/Summary from the Report menu.

104 User's Guide


Chapter 7 Designing Reports and Labels

You can place any of the report controls in any of the bands. You can also add user-
defined functions that are processed when the report is run. For more information
about user-defined functions in reports and labels, see Chapter 12, “Adding Queries
and Reports,” in the Developer ’s Guide.

Resizing Bands
You can modify the size and characteristics of each band.

> To resize a band


¢ Drag the band’s bar to the appropriate height.
Use the ruler to the left as a guide. The ruler’s measurement is specific to the height
of the band and does not include the page margins.

Tip You cannot make a band shorter than the height of the controls in the layout. Move the
controls within the band first, and then reduce the height.

Adding Report Controls


You can insert the following types of report controls in your report and label layouts.
To display Choose this control
Table fields, variables, and other expressions Field
Literal text Label
Straight lines Line
Boxes and borders Rectangle
Circles, ovals, boxes with rounded corners, and borders Rounded Rectangle
Bitmaps or general fields. Picture/OLE Bound

After placing the controls, you can change their format, size, color, position, and print
options. You can also add a comment to each control for your reference only; it does
not actually print in the report.

Adding Controls with Quick Report


Quick Report is a time-saving feature that automatically creates a simple report layout
for you. You select basic report components, then Visual FoxPro creates the layout
using your selections.
Tip You can use Quick Report in existing report files if the Detail band is empty. If the Page
Header band contains controls already, Quick Report preserves them.

For more information about the options in the Quick Report dialog box, see Help.

User's Guide 105


Part 3. Displaying Information

> To create a Quick Report


1 In the Project Manager, select Reports.
2 Choose New.
3 Choose New Report.
4 From the Report menu, choose Quick Report.
5 Select the table you want to use, then choose OK.

Quick Report dialog box


yf Quick Report

Field layout:

Clearto remove aliases.


——¥ Add alias
WM Add table
todata enviror

Select to define the report’s


data environment.

6 Select the field layout, title, and alias options you want.
7 If you want to select fields for the report, choose Fields and complete the Field
Picker dialog box.

Field Picker dialog box

Selected fields

C
Cc
fe
c
E;
c
Cc
[=

8 Choose OK.

The options you choose are reflected in the report layout.

106 User's Guide


Chapter 7 Designing Reports and Labels

Quick Report results in the Report Designer


ortDesigner - Report aS = ae Tk Page Header band
z contains field labels.

Page Footer band Detail band contains fields.


contains the date.

You can save, preview, and run the report as it is.


Note Quick Reports do not add general fields to the report layout.

Setting Report Data Sources


You can easily define the data sources that populate the controls in your report in the
report’s data environment. You can add tables or views and order the data using an
index from the table or view.

Using a view as a data source

<
Maneatis aioAge acircotates + |ny
Harvey Whitcomb | 19 Wa" i “<

Vivian Zimmer i

Grouped and ordered by a view Presented in a report

User's Guide 107


Part 3 Displaying Information

The data environment manages your report’s data sources by:


° Opening the tables or views when the report is opened or run.
* Populating the data set your report needs based on associated tables and views.
* Closing the tables when the report is closed or released.

To add a table or view to the data environment


From the View menu, choose Data Environment.
From the Data Environment menu, choose Add.
In the Add Table or View dialog box, select a database in the Database box.
VW
+
PoPIn the Select area, choose Tables or Views.
Your selection determines which fields list appears in the Tables in database box.
Data Environment Designer
- Report Designer - Repor'

company_na
contact_na
contact_ti
a a

5 Inthe Tables in Database box, select a table or view.


6 Choose OK.

You can set the order your records appear in your report by setting an index for the
data environment.

> To set an index for the data environment


1 From the View menu, choose Data Environment.
2 From the shortcut menu, choose Properties.
3 In the Properties Window, choose Cursor1 in the Object box.
4 Choose the Data tab and select the Order property.
5 Enter an index name.
Ore

Select an index from the list of available indexes.

For more information about modifying the data environment, see Chapter 9, “Creating
Forms,” in the Developer’s Guide, or search for “Data Environment Designer” in
Help.

108 User's Guide


Chapter 7 Designing Reports and Labels

For more information about integrating queries and other data sources, see Chapter
12, “Adding Queries and Reports,” in the Developer’s Guide.

Adding Field Controls


Your report or label can include field controls that represent values from table fields,
variables, and calculations.

> To add table fields from the data environment


1 Open the report’s data environment.
2 Select a table or view.
3 Drag fields onto the layout.

> To add table fields from the toolbar


‘| 1 From the Report Controls toolbar, insert a Field control.
2 In the Report Expression dialog box, choose the dialog button after the
Expression box.
3 In the Fields box, double-click the name of the field you want.
The table name and field name appear in the Expression for Field on Report box.
Note Ifthe Fields box is empty, add a table or view to the data environment.
You do not have to keep the table name alias in the expression. You can delete it or you can
clear the Expression Builder options. For more information, search for “Expression Builder”
in Help.

4 Choose OK.
5 Inthe Report Expression dialog box, choose OK.

For more information, see “Adding a Comment to a Control” later in this chapter. For
more information about commonly used report expressions or formatting a field
control, see Chapter 12, “Adding Queries and Reports,” in the Developer's Guide.

Adding Label Controls


Label controls are the literal text characters that you want to appear on the report. For
example, the label “Grand Total” identifies the contents of a field control containing a
total expression.

> To add a label control


1 From the Report Controls toolbar, choose the Label button.
2 Inthe Report Designer, click to place the control.

User's Guide 109


Part 3 Displaying Information

3 Type the characters for the label.


You can edit as you would in a text editor: use the ENTER key to adds lines or the
Edit menu to cut, copy, and paste text.

> To edit a label control


In the Report Designer, choose the Label button, then click the label you want to
edit.
2 Type the changes.

After placing the text, you can change its font and colors. For more information, see
the sections “Changing Fonts” and “Changing Control Colors” later in this chapter.

Adding a General Field


You can insert a General field containing OLE objects into your report.

> To insert a General field


1 In the Report Designer, add a Picture/OLE Bound control.
2 Inthe Picture From area, select Field.

Report Picture dialog box


‘ Report Picture

3 In the Field box, type a field name.


=6r=
Choose the dialog button to select a field or variable.

110 User's Guide


Chapter 7 Designing Reports and Labels

4 Choose OK.

The placeholder for the General field appears in the frame you defined. By default,
the picture retains its original size.
For more information about fitting your picture into the frame, see Chapter 12,
“Adding Queries and Reports,” in the Developer’s Guide.

Selecting, Moving, and Resizing Report Controls


If you created a report layout that already has controls on it, you can change their
placement and size on the report. You can change each control individually or you can
select a group of them and treat them as one unit.

> To move a control


¢ Select the control and drag it to a new position in a report band.
The control moves by increments into position within the layout. The increments
are based on the grid settings. To override the grid, press the CTRL key while you
drag the control.

> To select multiple controls


¢ Drag to draw a selection box around the controls.
Selection handles appear around each control. While they are selected, you can
move, copy, or delete them as a group.

You can associate a group of controls together for more than just the current task by
identifying them as a group. For example, you might want to associate a label control
and a field control with each other so you can move them without selecting them
separately. This feature is also useful after you have formatted and aligned the
controls because it preserves their positions with respect to one another.

> To group controls together


1 Select the controls you want to treat as a group.
2 From the Format menu, choose Group.
The selection handles move to the outside of the entire group. You can treat the
group of controls as a single unit.

> To ungroup a group of controls


1 Select the group of controls.
2 From the Format menu, choose Ungroup.
The selection handles appear around each of the controls that were in the group.

Once a control is on your layout, you can change its size individually or you can
resize a group of controls to match each other. You can resize any report control
except labels; their size is determined by the text, font, and point size.

User's Guide 111


Part3 Displaying Information

> To resize a control


Select the control, then drag one of the selection handles to the desired size.

> To match the size of multiple controls


1 Select the controls you want to have the same size.
2 From the Format menu, choose Size.
3 Choose the appropriate option to match the width, height, or size.
The controls resize to match the option you selected.

Copying and Deleting Report Controls


You can copy and delete any of the controls on the layout individually or as a group.

> To copy controls


1 Select the controls.
2 From the Edit menu, choose Copy then Paste.
A copy of the controls appears below the original set.
Drag the copy into position on the layout.

To delete controls
Select the controls.

From the Edit menu, choose Cut or press the DELETE key.

Aligning Controls
You can align controls in relationship to each other or you can place them according
to the grid provided by the Report Designer. You can align the controls with a
particular side or with the center.

> To align controls with each other


1 Select the controls you want to align.
2 From the Format menu, choose Align.
3 From the submenu, choose the appropriate alignment option. Visual FoxPro uses
the control whose edge is the closest to the direction you selected to align as the
anchor.

You can also use the Layout toolbar. Using the toolbar, you can align with the control
farthest from the side you select by holding the CrrL key down while clicking the
alignment button.

112 User's Guide


Chapter 7 Designing Reports and Labels

Left alignment tool

To align all the controls to this


control’s left edge, choose
Align Left Sides.

Als lign Left Sides}

To align all the controls to this control's left edge,


press CTRL and choose Align Left Sides.

Align the controls with an edge that all of the selected controls have open and away
from each other. Controls that are in a row and are selected to align with their right
side, or left side, will pile on top of each other. Likewise, controls that are in a vertical
line and selected to align with their top, bottom, will overlap. For more information
about the toolbars, search for the toolbar name in Help.

> To center controls within a band


1 Select the controls you want to align.
2 From the Format menu, choose Align.
3 From the submenu, choose Center Vertically or Center Horizontally.
The controls move to the vertical or horizontal center of their respective band.

Adjusting Control Placement


You can place a control in a specific position on the report page by using the status bar
or the grid. By default, controls snap into position according to the grid. You can
choose to turn off the snap feature and to show or hide the grid lines. Grid lines can
help you in positioning controls on the layout.

> To place a control at a specific position


1 From the View menu, choose Show Position.
2 Select the control, then move the control into place using the position information
on the status bar.

> To align controls manually


¢ From the Format menu, clear Snap to Grid.

User's Guide 113


Part 3. Displaying Information

> To display grid lines


¢ From the View menu, choose Grid Lines.
A grid appears in the report bands.

> To change the measurements of the grid


1 From the Format menu, choose Set Grid Scale.
2 Inthe Set Grid Scale dialog box, enter the number of pixels for the horizontal
width and vertical height of each square in the grid.

Grouping Data on Your Layout


After designing the basic layout, you may decide that grouping the records by certain
fields or other criteria would make the report easier to read. Grouping allows you to
separate groups of records visually and display introductory and summary data for
each group. The group break is based on a grouping expression. This expression is
usually based on one or more table fields but it can be as complex as you like.
When you have groups, your report layout has Group Header and Footer bands, to
which you can then add controls. Typically, Group Header bands contain the Field
control for the field used for the group. You may add lines, rectangles, rounded
rectangles, or any label you want to appear before the first record in a group. Group
Footers often contain group totals and other summary information for the group.
You can also specify other options for the groups:
¢ Printing text in headers and footers to identify specific groups
¢ Printing each group on a new page
¢ Resetting page numbers when groups are printed on a new page

If the data source is a table, the records are probably not in the appropriate order for
grouping. You can sort and order the data appropriately by setting an index on the
table, using an ordered view in the data environment, or using a query as the data
source to display the records in groups. The report layout does not actually sort and
order your data but processes the records in the same order that they exist in the data
source. Sorting and ordering must be done with a view, index, or other form of data
manipulation outside the layout.
For example, if a group breaks at the Region field, each time the report processes a
different region value, it produces a group. It does not recognize that a country at the
beginning of the table should be sorted to group with the same country at the end of
the table. For information on sorting and indexing, see Chapter 2, “Creating Tables
and Indexes,” Chapter 4, “Retrieving Data,” or Chapter 5, “Updating Data with
Views.” For more information about data sources, see Chapter 12, “Adding Queries
and Reports,” in the Developer’s Guide.

114 User's Guide


Chapter 7 Designing Reports and Labels

Adding a Single Group


A single group report has one level of data grouping based on an expression you enter.
For example, you can base a group on the field Country to print all records for the
same country together. The data source must be ordered by that field.

> To add a group


1 From the Report menu, choose Data Grouping.

Enter an expression.

Select to build an expression.

Select to prevent widow or


orphan group header lines.

2 In the first Group box, type the group expression.


= ype
Choose the dialog button to create an expression in the Expression Builder.
3 Inthe Group properties area, select the properties you want.
4 Choose OK.

After adding the expression, you can place any controls you want in the bands.
Usually, the Field control used for grouping is moved from the Detail band to the
Group Header band.

Adding Multiple Data Groupings


You can define up to 20 levels of data grouping within a report. Nested groups are
helpful for organizing data and totaling expressions for different levels.
To choose a level for a grouping, estimate how often the value might change, then
define the group that will change most often first. For example, your report might
need a grouping by region and a grouping by city. The value of a city field changes
more than the value of a region field; therefore, the city should be the first of the two

User's Guide 115


Part 3 Displaying Information

groups and the region should be the second. In this multiple group report, the table
must be sorted or indexed on a key expression such as Region+City.

> To add multiple groups


1 From the Report menu, choose Data Grouping.

Data Grouping dialog box

Enter the first group, whose values


change most, here.

Enter a second group here.

Select to prevent widow or


orphan group header lines.

2 In the first Group box, type the group expression.


2Or—
Choose the dialog button to create an expression in the Expression Builder.
3 In the Group properties area, choose the properties you want.
4 Choose Insert and repeat steps 2 and 3 for each grouping expression.
5 Choose OK.

Groups are numbered in the Data Grouping list in the order they are created. In the
Report Designer, the names of the group bands contain the number of the group and a
truncated group expression. The group headers and footers with the lowest number
appear closest to the Detail band.

Changing a Group Band


You can change the group’s expression and group printing options.

> To modify a group band


1 From the Report menu, choose Data Grouping.
2 In the Data Grouping dialog box, select a group expression to change.

116 User's Guide


Chapter 7 Designing Reports and Labels

3 Enter the new expression.


=Or=

Choose the dialog button to change the expression in the Expression Builder.
4 Change the grouping options as necessary.
Group properties in the Data Grouping dialog box

5 Choose OK.
6 In the Data Grouping dialog box, choose OK.

Deleting a Group Band


If you no longer need a particular group on your report layout, you can remove it.

> To delete a group band


1 From the Report menu, choose Data Grouping.
2 Select the group you want to delete.
3 Choose Delete.
The group band is removed from the layout. If the group band contains controls,
you are prompted to delete the controls as well.

Changing the Grouping Order


You can change the order of groups in a report after they have been defined. When
groups are reordered, all controls defined in a group band are moved to the new
location. Reordering groups does not change any previously defined controls. If boxes
or lines have been positioned relative to the top or bottom of a group band, they will
remain anchored in that band.

> To change the order of the groups


1 From the Report menu, choose Data Grouping.
2 Select the mover button to the left of the group you want to move and drag it to its
new position.

User's Guide 117


Part 3 Displaying Information

Customizing Your Layout


Once you create a report layout, you can customize it. Layouts created with the report
wizards and Quick Report are already customized based on the choices you made
while creating the layout. For example, the Mailing Label Wizard customized the page
setup by adding columns and setting the paper size. You can further customize the
layout and change the current settings with the Report Designer.

Tools for customizing your report layout


Title/Summary bands
Control formatting Grouping data

2 it De er- heport! 2 Microsoft


Page setup
Print

Data environment
Preview

You can change the data environment, page setup, or report controls. The data
environment defines the source for the data to include in the report, the page setup
defines the overall look of the report page and report bands, and the report controls
define items that appear on the page.

Defining the Report Page


When you plan a report, you usually have an idea of what the page will look like. For
example, you know the margins, the type of paper, and the layout you want. This
section describes setting the margins, the page orientation, and the height for the
bands of the report page.

118 User's Guide


Chapter 7 Designing Reports and Labels

For information about adding columns to your report page, see Chapter 12, “Adding
Queries and Reports,” in the Developer’s Guide.

Setting the Margin, Paper Size, and Orientation


You can set the left margin, paper size, and orientation for your report, as well as, the
column widths and space between columns for a multi-column report. In this context,
the word “columns” refers to the number of records that print across the page, not the
number of fields from a single record. The Report Designer does not display these
settings. It shows only the area within the margins that contains one record in a
column on the page. Also, if your report has columns and you change the left margin,
the width for the column will automatically change to accommodate the new margin.
If you change the paper size and orientation settings, make sure that the orientation is
correct for the paper size you select. For example, if you select an envelope, the
orientation should be set to Landscape.

> To set the left margin


1 From the File menu, choose Page Setup.

Page Setup dialog box

CABELL
LSD DMR ELLY
Set the left margin here.

See the changes to your layout here.

2 To set the margin, enter a number for the margin in the Left margin box.
The page image changes to display the new margin.
To select a paper size, choose Print Setup.
In the Print Setup dialog box, select a paper size from the Size list.
To select paper orientation, choose an orientation in the Orientation area, and then
choose OK.
6 Inthe Page Setup dialog box, choose OK.

User's Guide 119


Part 3 Displaying Information

Defining the Page Header and Footer


The controls placed in the Page Header or Page Footer bands appear once on each
page of the report. A report that has many pages should include the report name, page
number, date, and labels (if appropriate) in a header or footer.

Defining the Detail Band


Typically, the controls placed in the Detail band print once for each record. For
information about how to change the print options for each individual control, see
Chapter 12, “Adding Queries and Reports,” in the Developer's Guide.

Adding Title and Summary Bands


The Title band holds information that prints once at the beginning of the report and
the Summary band holds information that prints once at the end of the report. Both the
title and the summary can be on their own page. Fields with totaling expressions
become grand totals when placed in the Summary band.

> To add a title or summary band


1 From the Report menu, choose Title/Summary.
2 Select the bands you want.
3 If you want the band to appear on its own page, select New Page.
4 Choose OK.
The Report Designer shows the new bands.

Formatting Field Controls


After inserting a field control, you can change the control’s data type and print format.
Data types can be Character, Numeric, or Date. Each of these data types has its own
format options, including the option to create your own format template. The format
determines how the field is displayed when the report or label is printed.
Typically, you might convert all alphabetical output to uppercase, insert commas or
decimal points in numeric output, display numeric output in currency format, or
convert one date format to another.

Defining Field Control Formats


You can set a variety of format options for each data type.

> To format a field control


1 Double-click the Field control.
2 In the Report Expression dialog box, choose the dialog button after the Format
box.

120 User's Guide


Chapter 7 Designing Reports and Labels

3 In the Format dialog box, select the data type for the field: Character, Numeric,
or Date.
The Editing area displays the formatting options available for that data type.
Note This data type applies only to the report control. It reflects the data type of the
expression and does not change the data type of the field in the table.

4 Select the justification and format options you want.

The Format dialog box displays different options depending on the data type you
choose. You can also create a format template by entering characters in the Format
dialog box. For more information, search for “Format Template” in Help.

Justifying Text in a Field


You can justify field contents within the control in two ways. This setting does not
change the position of the control on the report, only the contents within the space of
the control.

> To justify text in a field control


1 Select the controls you want to change.
2 From the Format menu, choose Text Alignment.
3 From the submenu, choose the appropriate command.

\/ To justify text in a field


1 Double-click the Field control.
2 In the Report Expression dialog box, choose the dialog button after the Format
box.
Format dialog box for a Numeric expression

Enter template characters and codes here.

Select field
control formatting
options here.

User's Guide 121


Part 3 Displaying Information

3 In the Format dialog box, select the data type for the field: Character, Numeric,
or Date.
4 Select the justification and format options you want.

Changing Fonts
You can change the font and size of text for each field or label control or you can
change the default font for the report.

> To change fonts and size in a report


1 Select the control.
2 From the Format menu, select Font.
The Font dialog box appears.
3 Select the appropriate font and point size, then choose OK.

> To change the default font


1 From the Report menu, choose Default Font.
2 In the Font dialog box, select the appropriate font and point size you want as the
default, then choose OK.
Only the controls inserted after you changed the default font will reflect the new
font settings.

Adding Lines, Rectangles, and Circles


Lines, rectangles, and circles add visual interest to the layout of your report. You can
use them to separate or emphasize parts of your report.

Drawing Lines
You can add vertical and horizontal lines to your report layout with the Line control.
Often, you might want lines between the details contained in the body of the report
and the information in the header and the footer.

> To draw a line


1 From the Report Controls toolbar, choose the Line button.
2 Inthe Report Designer, drag to size the line.

After drawing the line, you can move or resize it, or change its thickness and color.
For more information, see the section later in this chapter.

Drawing Rectangles
You can draw rectangles on your layout to visually organize the information that
prints on the page. You can use them as borders around report controls, report bands,
or the entire page.

122 User's Guide


Chapter 7 Designing Reports and Labels

> To draw a rectangle


1 From the Report Controls toolbar, choose the Rectangle button.
2 In the Report Designer, drag to size the rectangle.

Drawing Rounded Rectangles and Circles


You can draw circles or rectangles with a variety of rounded corners.

> To draw a rectangle or circle


1 From the Report Controls toolbar, choose the Rounded Rectangle button.
2 Inthe Report Designer, drag to size the control.
3 Double-click the control.

Round Rectangle dialog box


ound Rectangle
oy We

Choose a style for the


rectangle’s corners.

4 In the Style area, select the corner style you want.


5 If appropriate, set position options.
6 Choose OK.

Changing Line Thickness or Style


You can change the thickness of lines used for vertical and horizontal lines,
rectangles, and rounded rectangles from a hairline to 6 points wide. You can also
change the style of the line from dotted to a combination of dots and dashes.

User's Guide 123


Part 3 Displaying Information

> To change line size or style


1 Select the line, rectangle, or rounded rectangle controls you want to change.
2 From the Format menu, choose Pen.
3 From the submenu, select the appropriate size or style.

Adding a Picture
You can insert a picture as part of the report. For example, a company logo can appear
in the page header of an invoice. Pictures from a file are static; they do not change
with each record or group of records. If you want to change the display depending on
the record, insert a General field instead.

> To add a picture


1 From the Report Controls toolbar, choose the Picture/OLE Bound Control
button.
2 Inthe Report Designer, drag to size the picture.

Report Picture dialog box


Report Picture

—1c\vip\samples‘\mainsamp\bitmay
z SENS

In the Picture from area, select File.


In the File box, type a file location.
IOre
Choose the dialog button to select a file of type .BMP or .ICO.
If appropriate, set the size, position, or print options.
Choose OK.

124 User's Guide


Chapter 7 Designing Reports and Labels

_ Changing Control Colors


You can change the color of a field, label, line, or rectangle.

> To change colors


1 Select the controls to change.
2 In the Color Palette toolbar, choose Foreground Color or Background Color.

3 Select the color you want.

Adding a Comment to a Control


While creating or changing a control, you might want to include a description. The
dialog box for each control offers a comment box. These comments are saved with the
layout file but do not appear in the printed report or label.

> To add a comment to a control


1 Double-click the control.
2 In the control’s dialog box, enter your comment in the Comment box.
3 Choose OK.

Previewing and Printing Your Report or


Label
After starting your report or label layout, you can preview the results of your work or
print a report or label. You can preview at any time while you are customizing it.
For more information about setting a control’s print options or setting page breaks, see
Chapter 12, “Adding Queries and Reports,” in the Developer’s Guide.

| Previewing Your Results


By previewing a report, you can see how it looks on the page without printing it. For
example, you can check the alignment and spacing of the columns of data, or see if
the report is returning the data you want. You have two choices: view an entire page
or zoom in on a portion of a page.
The Preview window has its own toolbar with buttons that move you from page to
page in the report.

User's Guide 125


Part 3 Displaying Information

eee i Fen ee ge ee ee
Caution [Ifyou get the prompt, “Do you want to save changes to your file?”, you have selected
to close not just the Preview window, but also the layout file. You can select Cancel to return to
Preview mode or Save to save your changes and close the file. If you select No, any changes
you made to the layout will not be saved.
oA ome A ai Ne ae ke ss oh elie FO eee

> To preview your layout


1 From the View menu, choose Preview.

Report Preview
Previous page Next page

First page Last page Return to design mode.

nx - Pag Microsoft Visual FoxP


: - SE

Select a page number.


yw List of Contacts
Zoom control -

Maria Anders Sales Alfreds 030-00743

Click on page to toggle


between two different Rng TeMo Ate Owner Ana Trujillo
Zoom settings. ——
Antonio Moreno Owner Antonio Moreno

Thomas Hardy sales Around the Horn

2 In the Print Preview toolbar, choose Previous Page or Next Page to switch pages.
3 To change the size of the report’s image, choose Zoom.
4 To print the report, choose Print.
5 To return to design mode, choose Close Preview.

Printing Reports
The report or label layout file you create using the Report Designer is a shell that
formats the data into a pleasing display for printing. It processes the records in the
order they appear in the data source. If you use data directly from a table, the data is
not sorted and ordered for any groups that may be in the layout. Before printing a
report file, you should verify that the data source will sort and order the data
appropriately. If the table is part of a database, you create a view and add it to the
report’s data environment. The view sorts and orders the data for you. If the data

126 User's Guide


Chapter 7 Designing Reports and Labels

source is a free table, you can create and run a query that uses the report as its
destination. For more information about views, see Chapter 5, “Updating Data with
Views.” For more information about queries, see Chapter 4, “Retrieving Data.” For
more information about controlling the records that print in your report, see Chapter
12, “Adding Queries and Reports,” in the Developer’s Guide. If you do not need to
sort or order the data, you can print the report from the Report Designer.

> To print a report


1 From the File menu, choose Print.
2 Choose OK.
Note Ifthe data environment is not set, the Open dialog box appears with a list of tables
from which you can select.
Visual FoxPro sends the report to the printer.

User's Guide 127


‘ _ ; _ a - ~~ = a 7 —— < = -— 2 oa

7 j 2 — . re -

Ai Vm cet ga nly © rile

Beedle: © at, 2 oe Oe gas Th ta ty ae i eas


Sang Resa grloge & ate % oe é
sabe, Qe” Cae al” Na 4S
|
an ig.
RE yeata ss
DRMa Li ete Ton iad ihe. i i
| se
< OP 656 Yona al a SR }ane sdLalta
a ‘=

a> Xe « a
“ag ba =

ples =
by / : :
ahd ht : etn r i Pan wc pia
S580 on crane
6a La t = f

~ my

a aba a
- 7 Fé 7

=< o Fr a a oe
See Re <y
~ a ~ cs 7 s ;

. a we
pS i =
;
7S i
~ ®

a g
: ~ ~ 7a"
‘ :

= ="

| 7 4 .

|
~ -
Stati
Sa

4 —
a .

Pe Cll) ete
7 ‘ ™!
CHAPTER 8

Managing Data Through Forms

Just as reports make it easy to print your tables and queries, forms provide a
convenient way to display, enter, and edit your database information. You can create
forms that mimic the paper forms you’re used to, providing a familiar data entry
environment.
This chapter shows how to create interactive forms from tables and views, using form
wizards, builders, and the Form Designer. For information about using forms as the
basis for building an application, see Chapter 9, “Creating Forms,” in the Developer’s
Guide.
This chapter discusses:
¢ Creating Forms
¢ Adding Controls to a Form
¢ Modifying a Form
¢ Customizing Forms

Creating Forms
Forms display the fields and records in your tables and views, and usually include
navigation controls to help you move from record to record.
You can create forms in Visual FoxPro in any of these ways:
* Use form wizards to create ready-to-use forms.
* Choose Quick Form on the Form menu to create a simple form that you can
customize by adding your own controls.
* Use the Form Designer to modify existing forms or create your own forms.

User's Guide 129


Part 3 Displaying Information

Using a Form Wizard


Whenever you want to create a new form, you can use a form wizard to help you set it
up. The wizard will ask you a series of questions and build a form for you based on
your answers. You can choose from several different style options and preview your
form before creating it.

> To create a form with a wizard


1 Inthe Project Manager, select the Documents tab and select Forms.
2 Choose New.
3 Choose Form Wizard.
4 Select the type of form you want to create.
5 Follow the instructions on the wizard screens.
Two form wizards are available to help you create forms.
4

You can also access the form wizards from the menu by choosing the Wizards
command from the Tools menu, and selecting Form.
Visual FoxPro provides two different form wizards to help you create forms:
¢ To create a basic form based on one table, choose the Form Wizard.
* To create a form that incorporates data from two tables linked in a one-to-many
relationship, choose the One-to-Many Form Wizard.

Forms you create with the form wizards have a standard set of navigation buttons so
you can display different records in the form, edit records, search for records, and so
on.

Starting the Form Designer


If you want to create your own form without using a wizard, use the Form Designer.
With the Form Designer, you can add fields and controls to your form, and customize
it by adjusting and aligning the controls.

130 User's Guide


Chapter 8 Managing Data Through Forms

The Quick Form command is provided to make it easier to get started creating a form.
The Quick Form command displays the Form Builder, which adds selected fields from
tables or views to your form.

> To create a new form


1 Inthe Project Manager, choose the Documents tab.
2 Select the Forms icon.
3 Choose New.
4 Select New Form.

The Form Designer window appears so you can begin creating your form.

The Form Designer window

4 Form Designer <FomDoct,

Form windows for the form Add controls to the form


you are designing. with the controls toolbar.

Adding Fields Quickly


When you want to quickly place the fields from a table or view into a form, choose
Quick Form on the Form menu. Quick Form starts the Form Builder, which adds
selected fields from a table or view to your form, using the field style you choose.

User's Guide 131


Part 3 Displaying Information

The Form Builder helps you quickly create a form from a table or view.
‘sf Form Builder

No_in_unit
Unit_price
_ {Unit_cost

> To add fields to a form with the Form Builder


1 In the Form Designer, select Quick Form from the Form menu.
2 Make your field and style choices in the Form Builder and choose OK to generate
the form.

The Form Builder creates a form without navigation controls, so you can add your
own. You can use a control builder to add navigation controls to your form, or choose
from the predefined library of navigation controls provided with Visual FoxPro. For
more information, see “Adding Controls to a Form” later in this chapter.

Saving Forms
When your form is finished, you can save it for future use.

> To save a form


¢ In the Form Designer, choose Save from the File menu.

Forms are saved as files with an .SCX extension.

Running a Form
Once you have saved a form, you can run it to see how it works.

> Torunaform
¢ In the Project Manager, select the name of the form under the Documents tab and
choose Run.
—Or-
¢ From the Form menu, choose Run Form.

132 User's Guide


Chapter 8 Managing Data Through Forms

You can also choose the Run button on the Standard toolbar.

Tip When running a form, you can quickly switch to design mode by clicking the Modify Form
button on the Standard toolbar.

Adding Controls to a Form


You add new controls by selecting them from the Form Controls toolbar, and placing
them in the Form Designer window. For example, you might want to add new labels
for fields on the form, add new controls such as buttons, edit boxes, list boxes, and so
on, or add pictures or lines and shapes to enhance the appearance of your form.

> To add a control to a form


1 Choose a control in the Form Controls toolbar.
2 Inthe Form Designer window, drag to create a rectangle where you want the
control to be, or click to create a control of default size.

The new control appears where you placed it. You can then move it to its final
location on the form, and resize it as needed.

If you want help adding a control, you can use a builder to add the controls and make
them work with the form, or you can add the controls using the Form Controls toolbar
and the Properties window.

Adding Controls to a Form with a Builder


Just as wizards can be used to construct forms quickly, builders can be used for adding
controls to a form. The builder asks a series of questions related to the control you are
adding to your form, and sets the appropriate properties to make the control work as
desired.
For example, if you want to add a new text box to a form, the builder asks which style
of text box you prefer and which table’s field it should display.
Builders can be accessed in one of two ways: from the Form Designer shortcut menu,
or by activating the Builder Lock button on the Form Controls toolbar when you add
controls to a form.

> To add a control with a builder


1 Inthe Form Controls toolbar, select the Builder Lock button.
2 Select the control you want from the Form Controls toolbar, and draw it on the
form.
3 Fill in the information on the builder tabs.

User's Guide 133


Part 3 Displaying Information

Adding Fields to a Form with the Form Builder


A quick way to add a new field to a form is to use the Form Builder. Even if you
already have fields on your form, you can add new fields that match the style of
existing fields. You can also choose different sources for the fields you add to the
form, making it easy to add fields from other tables or views to your form.

> To add fields to a form


1 In the Project Manager, open the form.
2 From the Form menu, choose Quick Form. The Form Builder appears.
3 In the Style tab, select the style you want for the new control.
4 In the Field Selection tab, select the source of the fields, and the fields you want to
add.
5 Choose OK.

Using Builders for All Controls


By setting the Builder Lock button on the Form Controls toolbar, you can
automatically use a control builder each time you add a control to a form.

> To turn on the Builder Lock


¢ Inthe Form Controls toolbar, click the Builder Lock button.

Adding Controls to a Wizard-Generated Form


If you create a form with one of the form wizards and then want to add controls to it,
you can match the style of the existing controls by using the controls in the wizard
controls library, WIZSTYLE.VCX.
When you open the wizards control library, wizard-style controls (such as
chiselfield, embossedmemo, and so on) are available in the Form Controls
toolbar. To find out which control to use, select an existing control and note its class
and class library. For example, a standard wizard field would be in the
Standardfield class, found in WIZSTYLE.VCX.

Tip Use ToolTips on the Form Controls toolbar to help you identify class names.

> To match controls in a wizard-generated form


1 Inthe Form Designer, open the form.
2 From the Form Controls toolbar, choose the View Classes button and choose
Add.
3 In the Open dialog box, locate WIZSTYLE.VCX in the WIZARDS subdirectory
and choose OK.

134 User's Guide


Chapter 8 Managing Data Through Forms

4 In the Form Controls toolbar, select the control that corresponds to an existing
control in the form and drag in the form to add it.

Note If you move a form to a new directory or another system, you should move the contro!
library associated with the form along with it.

Adding Controls and Setting Control Properties


To add a new control to a form without using a builder, just select the control you
want from the Form Controls toolbar, and drop it on the form.
Some controls, such as labels, shapes, and lines, do not display data from a table or
view, or perform an action. But most other controls do, and you need to tell Visual
FoxPro what field you want them to display, or what action you want them to perform.
For example, you usually want a text box to display the value from a field, and a
button to execute a command.

To make new controls work properly in your form, you need to associate, or bind
them with the table and field you want them to display. You link the control to its
control source—the data you want it to display or the field where you want entered
data to be stored—by setting the ControlSource property in the Properties window.
For example, if you add a new text box to a form, you need to tell Visual FoxPro
where to get the values for the text box by setting the ControlSource property to point
to a field in a table or view. You can then set other properties to control the appearance
of the control.
A tool called the Data Environment Designer makes it easy to add a new field to a
form and set the ControlSource property for the field.

Setting Up the Data Environment


By placing the tables or views associated with your form in the data environment for
your form, you make it easy to bind new controls to the fields in the tables or views.
When you have finished setting up a data environment, the ControlSource property
field displays the fields available in the Data Environment Designer so you can select
the one you want to bind to the control.
If you are editing a form created by a wizard, you will find that the data environment
for your form is already populated with the tables or views you used when setting up
the form with a Form Wizard.

User's Guide 135


Part 3 Displaying Information

> To display the data environment


¢ In the Form Designer, choose Data Environment from the View menu.
Data Environment Designer
a * Data Environment - FormDoc!

emp_id
last_name
first_name
title
birth_date

> To add a table or view to the data environment


1 From the Data Environment menu, choose Add.
Note Ifthe data environment is empty, the Add Table or View dialog box appears
automatically.

2 Inthe Add Table or View dialog box, select Tables or Views.


3 Select the table or view you want to use.
4 Choose Add.

Note To add views to the Data Environment Designer, you must have a database open.

Adding a Control to a Form


The Form Controls toolbar makes it easy to add a new control to your form so you can
display a field from your table or view. You’ll want to select the type of control
appropriate to the type of field you are displaying. For example, use a text box control
to display a single-line field or select an edit box control to display a memo.
The Properties window displays all the properties for the controls you add to a form.
You use the ControlSource property in the Properties window to bind the control you
have added to your form to a specific field in the table in your Data Environment
Designer.

> To display the Properties window


¢ From the View menu, choose Properties.

Note If you want to use the Properties window to set control properties, make sure Builder
Lock is turned off.

136 User's Guide


Chapter 8 Managing Data Through Forms

> To add a new field to a form


1 Inthe Form Controls toolbar, choose a data control and drag in the Form Designer
window to create the control.
2 In the Properties window, choose the Data tab and select the ControlSource
property.

3 Enter a field name.


—Or-
Select a field from the list of available fields.

Available fields for the ControlSource property of a control


fy Properties -FormDoc! & Ea)

Al Date |Metho| Layo] ot


Riel Click here to display available fields
employee.emp_id for the ControlSource property.
employee.last_name

employee. hire_date
employee. address

Adding Multiple Controls at One Time


When you choose the Button Lock button, you can add multiple controls of the same
type without having to click the control button on the toolbar more than once. For
example, if you want to add five text boxes to a form, make sure the Button Lock
button is selected, then click the text box control button in the Form Controls toolbar
once and add all five text boxes to the form.

Button lock is automatically engaged if you double-click on a control button on the


Form Controls toolbar. To turn button locking off, click the Button Lock button again
or click the Selection Pointer button on the Form Controls toolbar.

Adding Controls Quickly


You can quickly create single or multiple controls by clicking on fields or tables and
dragging them directly onto a form. You can drag fields or tables from any of the
following data sources and drop them on a form or a container class that you are
designing:

User's Guide 137


Part 3 Displaying Information

Data Environment Designer


Database Designer (Single tables, single local views, single remote views, single
fields, multiple fields).
Project Manager (Single tables, single local views, single remote views, single
fields)

When you drag a field or table onto a form, Visual FoxPro determines what type of
control to create based on options you set.

Setting Field Mapping Options


You can specify the type of control that is created when you drag a field or table onto
a form. For example, you can create a text box control any time a Character field is
dragged onto a form.

> To map field types to classes


1 From the Tools menu, choose Options.
2 Select the Field Mapping tab.
3 To change a field type mapping, select a line in the Map fields to classes for drag
and drop area and choose Modify.
In the Modify Field Mapping dialog box, select a field type from the Type list.
To set the class that is created whenever you drag a table or multiple fields, select
Multiple from the Type list.
To select the class library (.VCX file) that contains the control you want to
associate with the selected field type, choose Browse.
Select a class name from the Name list. The class you specify here will be created
any time a field of the selected type is dragged onto a form.
Choose OK to accept the mapping.
Set options in the Database options area:
To Select
Create a label in addition to the bound control when Drag and drop field caption
you drag a field or table to a form or container
Set the Comment property of the bound control to Copy field comment
the text specified in the Field Comment box in the
Fields tab of the Table Designer
Set the InputMask property of the bound control to Copy field input mask
the input mask specified in the Fields tab of the
Table Designer.
Set the Format property of the bound control to the Copy field format
format specified in the Fields tab of the Table Designer.

138 User's Guide


Chapter 8 Managing Data Through Forms

Note You can also specify classes for dragging and dropping in the Display Class box in the
Fields tab of the Table Designer. The settings in the Table Designer override the settings you
specify here.

Quickly Creating a Single Control


You can quickly create a single control based on the field type mapping you specified
on the Field Mapping tab in the Options dialog box. You can also override the default
mapping and create a different class type.

> To create a single control


¢ Click on any field in the Data Environment and drag it onto a form.

Note The ControlSource property of the newly created control is set to the Name property of
the field.

> To create a single control and override the current field mapping
1 Right-click on any field in the Data Environment and drag it onto a form.
2 From the shortcut menu, select Create Other Control Here.
3 In the Open dialog box, choose a Visual Class Library (.VCX) file.
4 Select the type of control you want to create from the Class Name box and choose
Open.

Quickly Creating Multiple Controls


You can drag an entire table onto a form. By default, a grid control is created when
you drag a table onto a form. You can override the default and create multiple controls
corresponding to the default field type mappings specified for each field in the table.

> To create a grid control


* Choose any table in the Data Environment, Database Designer, or Project
Manager and drag it onto a form.

> To create multiple controls


1 Right-click any table, or two or more highlighted fields in a table, in the Data
Environment, Database Designer, or Project Manager and drag it onto a form.
2 From the shortcut menu, select Create Multiple Controls Here.

Modifying a Form
If the wizard- or builder-generated forms don’t quite fit your needs, you can modify
them with the Form Designer. Using the Form Designer, it’s easy to move and resize
controls, copy or delete controls, align controls, and modify the tab order.

User's Guide 139


Part3 Displaying Information

> To modify a generated form


1 In the Project Manager, select the Documents tab.
2 Choose the Forms icon and select the name of the form.
3 Choose Modify.

Using the Form Designer Toolbars


The Form Designer toolbars give you quick access to frequently used commands and
the layout, alignment, and color controls you need when designing or modifying
forms. For more information about the purpose of each button on each toolbar, you
can use the ToolTips feature or search for “Toolbars” in Help.

The Form Designer toolbars

The Form Controls


toolbar contains y sy Form Designe
different control oats
ee. alae
sey

types youcanaddto = = [reecst — The Form Designer toolbar makes it easy


your forms. — == to set design modes and control the
— display of related windows and toolbars.

The Color Palette


toolbar makes it easy
to set the color of mi The Layout toolbar lets you align and
forms and controls. —~ :
(mmf size controls relative to each other.
Dt ist

Selecting, Moving, and Resizing Controls


After creating a form, you may need to adjust the placement or size of the controls on
the form. For example, you might want to move a memo field, or make a text box
longer.

> To select a control


¢ Using the pointer, click anywhere on the control.

> To select adjacent controls


1 Choose the select arrow in the Form Controls toolbar.
2 By dragging the pointer, draw a box around the controls you want to select.

140 User's Guide


Chapter 8 Managing Data Through Forms

> To move a control


1 Select the control by clicking it.
2 Drag the control to the new position in the form window.
aOre
Select the control and use the arrow keys to reposition it.

> To resize a control


1 Select the control.

2 Drag one of the sizing handles to increase the length, width, or overall size of the
control.

Copying and Deleting Form Controls


When designing or modifying a form, you may want to make a copy of a control
which is already on the form. You can copy an existing control and paste the copy
onto your form.

> To copy a control


1 Using the pointer, select a control.
2 From the Edit menu, choose Copy.
3 From the Edit menu, choose Paste.
4 Use the pointer to reposition the control as needed.

If you create a control and then decide you don’t need it, or don’t want a control
created by a wizard, you can remove the control.

> To delete a control


1 Select the control and choose Cut from the Edit menu.

Aligning Controls
The buttons on the Layout toolbar make it easy to accurately line up controls in
relation to each other in your forms. For example, you might want to align controls
horizontally or vertically or make sure that a related set of controls has the same width
or height. To align controls, select a group of controls, and then choose one of the
layout buttons on the Layout toolbar.
For more information, see “Aligning Controls” in Chapter 7, “Designing Reports and
Labels,” or search for “Layout Toolbar” in Help.

User's Guide 141


Part 3 Displaying Information

Adjusting Control Placement


If you need to place controls precisely on the screen, you can use Show Position on
the View menu. When checked, Show Position displays the coordinates and
dimensions of a selected control in the status bar at the bottom of the Form Designer
window.

Control coordinates and dimensions shown in the status bar

Controlling the Grid Display


The grid display helps you align controls on your forms. You can adjust the size of the
grid with Set Grid Scale on the Format menu. You can turn display of the grid on and
off by using the Grid Lines command on the View menu, or setting the Grid Lines
option on the Forms tab of the Options dialog box.
You can also adjust the size or position of controls in relation to the grid with Snap to
Grid on the Format menu. When Snap to Grid is checked on the Form menu, controls
placed on a Form are automatically aligned to the guidelines on the grid. You can
override the grid by:
¢ Clearing Snap to Grid on the Format menu. By default, this option is checked.
¢ Using the arrow keys to align controls.
¢ Pressing CTRL before clicking on a control and holding the CTRL key down while
dragging the object to another position.
* Choosing alignment options from the Layout toolbar or the Format menu.

Setting Tab Order for Controls


The tab order of a form determines the sequence in which the controls are selected
when a user presses the TAB key to move through the form.
You can choose two different methods for setting tab order: interactively, by clicking
the controls in the order you want them to be selected when the form is used; or by
arranging a list of controls in a dialog box.

> To choose a tab ordering method


1 From the Tools menu, choose Options.
2 Inthe Options dialog box, choose the Forms tab.
3 Under the Tab Ordering option, select Interactive or By List.

142 User's Guide


Chapter 8 Managing Data Through Forms

Setting Tab Order Interactively


In interactive mode, you set tab order by double-clicking the control you want to be
first in the tab order, then single-clicking on the rest of the controls in the order in
which you want them to be selected in the form.

> To change the tab order interactively


1 From the View menu, choose Tab Order.
2 Double-click the tab order box beside the control you want to be the first control in
the tab order.
Click the tab order box for each of the other controls.
Click anywhere on the form to save your changes and exit Tab Order mode, or
press ESC to exit Tab Order mode without saving your changes.

Setting Tab Order by List


In list mode, you set tab order by rearranging the control names in the Tab Order
dialog box. You can set order by row (down the form) or by column (across the form).

Setting tab order by arranging a list of controls

Drag the control names up or down


in the list to set the tab order.

To set the tab order using a list


From the View menu, choose Tab Order.
Choose By Row or By Column.
In the Tab Order dialog box, use the pointer to rearrange the list.
VW
=—-
DM
Oo
PF Choose OK.

Customizing Forms
You can add enhancements to your forms to make them more visually interesting and
easier to use. For example, you might want to group similar controls together visually
by drawing a box around them, or use bitmaps to give the forms a more professional
appearance.

User's Guide 143


Part 3 Displaying Information

Using the Form Designer, you can customize your forms by:

° Changing text fonts and sizes


e Adding shapes and lines to a form
e Adding graphics to a form
¢ Setting the foreground and background colors of a form

Changing Text Fonts and Sizes


Using the font properties in the Properties window, you can modify the style and size
of the text that appears in controls you have added to your forms. You can choose
from the available font styles and sizes supported by your system. To change the text
in your form, change the font properties, such as FontName, FontSize, and FontBold,
shown in the Properties window.

> To change the text in your forms


1 In the Form Designer, select the control you want to change.
2 Inthe Properties window, drop down the Object list, and select the object you
want to change.
3 Locate the font property you want to change, and set its value.

Adding Shapes and Lines to Forms


You can add shapes and lines to forms to customize them. For example, you may want
to separate groups of controls with a dividing line, or enclose related controls within a
box to set them apart.

> To add aline to a form


1 Inthe Form Controls toolbar, choose the Line button.
2 Drag in the form to create a line.

You can size and move the line like other controls, or change the slant of the line with
the LineSlant property in the Properties window.

> To add a shape to a form


1 In the Form Controls toolbar, choose the Shape button.
2 Drag in the form to create a shape.

You can change the type of shape drawn with the Curvature property in the Properties
window.

144 User's Guide


Chapter 8 Managing Data Through Forms

Adding Graphics to a Form


You can add a graphic to the background of your form, or add a picture to a box inside
the form.

> To add a graphic to your form


1 Choose one of the following:
¢ To change the background of the form, select the form.
IGTes
¢ To add a picture to your form, select an Image control from the Form Controls
toolbar and place it on the form.
2 In the Properties window, select the Picture property.
3 Choose the dialog button to display the Open dialog box.
4 Locate the bitmap or other file you want to use.
5 Choose OK.

Setting Form Colors


You can control a form’s colors by using the ColorSource property to base the colors
on an existing color scheme, or you can use the Color Palette toolbar to change the
foreground or background color of your forms and the controls within them.

> To set form colors using the ColorSource property


¢ On the Layout tab in the Properties window, choose ColorSource and select a
value.

> To set the foreground or background color of a form or control


1 From the View menu, select Color Palette toolbar.
2 Choose Foreground Color or Background Color.
3 Select the control or form you want to change.
4 Inthe Color Palette toolbar, select the color you want to use.
5 To see more color choices, choose Other Colors on the toolbar.

Vv To create a custom color


In the Color Palette toolbar, choose Other Colors.
—_
Se In the Color dialog box, choose Define Custom Colors to display the Custom
Color Selector.
3 Select one of the Custom Colors boxes, then click in the Custom Color Selector
to select the custom color you want.

User's Guide 145


Part 3 Displaying Information

4 Choose Add to Custom Colors to add the new color to your palette.
5 Choose OK.
Visual FoxPro applies the custom color to the current selection.

Setting the Maximum Form Design Area


Setting the form design area lets you customize forms to ensure that they display
properly under specific resolutions. For example, if you know that users with 640x480
screen resolution will be using the form you are designing, you should not select
1024x768 as your maximum design area.

> To set the maximum form design area


1. From the Tools menu, choose Options.
2. In the Forms tab, select a value for Maximum Design Area.

Tip If you select None, the Form Designer will not impose a limit on the size of form you can
design.

146 User's Guide


PART 4

Using Visual FoxPro with Other


Applications

If you need to get information to and from other formats, or if you


need to communicate with other applications, Visual FoxPro gives
you all the tools necessary to convert files, and to take full
advantage of OLE technology.

Chapter 9 Importing and Exporting Data


If you have data in files produced by other applications, such as
spreadsheets and word processors, you can easily import this data
into Visual FoxPro and incorporate it into your tables.

Chapter 10 Sharing Information with Other Applications


When you want to share information with other applications, or
incorporate the functionality of other applications into your tables,
reports, forms, and applications, you can use the OLE capabilities in
Visual FoxPro.

User's Guide 147


i

b T Hees A ‘-¢ ‘>v \e = RPS —

| ite iw ciduaiLisuaiv ‘sathhy


rawitenitqep’ Por Deng? i ew
r ro hy ©. Teary
= é *>, * 6 v ee tna! ——
Bi a > re 1 o &% ww “ =_* ——
= 7 0 bite a e ~

Peet oer
A,
Menoril oene > “S
etna Pode moat bag Meeeaatie ‘ery po) tenwere
=
2
if PPG iV OSnEgE Med cLliyy Caneieesrreeetees o
* Teenie’ Sant al tagenrr. J vincraasn ent oa 16 ney
* 2 _ SPP Sb 30 egies
-, eee Faby %6 BIS BANS § or) Sw =<

.. ...* atest
oninugbum gnihoqa
nd d @
>, ~~ —— BB hae cue Decide Brito Val tre piteety all} yt alah aynt
mt eok WE
amit vite fithiyi5 ions Ne ae Cnet BindSioadtoberrge
y:. cote IMI Beaten Die ttt ey omit
nab aii i hemi pate etweigadid =
. eb igi Rae NEW adiatnaty) yale agteme ee
Biasdiay Cy MAte A
NE dO hepigun ll STsMaltSiete =.
oc Peto 7 IG bons sie ed delta or Putoo’ eringa

=
a
~)
~
i
~

“~~

Tht Bl wet) : > Fi:


(i Oucop Opie
CHAPTER 9

Importing and Exporting Data

You can copy data between Visual FoxPro and other applications by importing to and
exporting from Visual FoxPro. The data can be in any one of a variety of text,
spreadsheet, and table file formats. You can create a new Visual FoxPro table, add to
an existing Visual FoxPro table, or copy data to a different file type.
For more ways to share data with other applications, see Chapter 10, “Sharing
Information with Other Applications.”
This chapter discusses:
¢ Understanding Importing and Exporting
¢ Importing Data
¢ Appending Data
¢ Exporting Data

Understanding Importing and Exporting


You can choose from three ways to copy data from outside of Visual FoxPro:

1. Importing
2. Appending
3. Exporting

When you import or append data, you bring the data from another application into
Visual FoxPro. When you export data, you send data from a Visual FoxPro table to a
file type used by another application. These methods allow you to copy and use, rather
than link or share, the data. If you prefer to create links between applications, see
Chapter 10, “Sharing Information with Other Applications.”

User's Guide 149


Part 4 Using Visual FoxPro with Other Applications

Importing and appending data to Visual FoxPro tables

Importing
to new...

fico
“\Cust_id| Contact 2
ET
Oe
: [Postalcode + ..ofF appending to
}
existing tables.

ales Representative

When you import data, you copy data from a source file, create a new table, and
populate the table with the file’s data. For example, you can import the data from a
dBASEs table to create a Visual FoxPro table. After importing a file, you can use it
like any other Visual FoxPro table.
When you append data, you add the source data to a Visual FoxPro table after the last
record in the table. You can specify fields to import and select records that meet a
condition in an expression. After appending from the file, you can view and edit the
records in the Visual FoxPro table.
When you export, you copy data from a Visual FoxPro table into a new file formatted
for use in another application. For example, you can export Visual FoxPro data to a
Microsoft Excel worksheet file.

150 User's Guide


Chapter 9 Importing and Exporting Data

Exporting data from Visual FoxPro


{mg Customer
_ |Cust_id
s Representat

les Representative
DIF
WK
.WK1
Ouwner

Patricio Simpson

You select the source and destination files. You can also specify fields to export, set
the scope of records to export, and select records that meet a condition.

Importing Data
If you want to import from your source file, you can either let Visual FoxPro define
the structure of the new table or use the Import Wizard to specify its structure. Visual
FoxPro uses the field order in the source file to define the structure of the destination
table. If you want to define the structure, you can modify the file in the source
application or use the Import Wizard.
If you no longer have access to the application that supports the source file and you
want to change the order or data type of the fields, you can import the source file, then
create a query that outputs the fields in the order you want to another new table. For
more information, see Chapter 4, “Retrieving Data.”
When you import a file, you must choose the file type you want to import and specify
the source file and destination table names.

Choosing a File Type to Import


The following table lists the file types you can import into Visual FoxPro.
File Type File Extension Description
Microsoft# Excel XLS A Microsoft Excel (versions 2.0, 3.0, 4.0,
and 5.0) worksheet format. The column
cells become fields, and rows become
records.

User's Guide 151


Part 4 Using Visual FoxPro with Other Applications

File Type File Extension Description

Lotus 1-2-3@ WKS A Lotus 1-2-3 spreadsheet for releases 1-A,


WKI1 2.x, and 3.x. The column cells become
WK3 fields and rows become records.

Borland@ Paradox® DB A Paradox table for versions 3.5 and 4.0.

If you want to use tables from a previous version of FoxPro or use dBASE files, you
can open and use them without importing. Visual FoxPro will ask if you want to
convert the table to Visual FoxPro 5.0. Once you convert a table from a previous
version, this table cannot be opened in the previous version.
For more information on importing files, search for IMPORT in Help.
For considerations which affect importing Microsoft Excel, Lotus, and Microsoft
Access data, see “Choosing a File Type to Import” later in this chapter.

Importing Data with the Import Wizard


The Import Wizard helps you to create a new table from your source file. The wizard
asks you a series of questions, imports the file based on your answers, and allows you
to control how the new table is structured.

> To import a file with the Import Wizard


1 From the File menu, choose Import.
2 From the Import dialog box, choose Import Wizard.
3 Follow the instructions on the wizard screens.

Importing Data into a New Table


You can import data from a table or spreadsheet format using the source file’s
structure to define the new table.

> To import data to a new table


1 From the File menu, choose Import.

152 User's Guide


Chapter 9 Importing and Exporting Data

Import dialog box

Enter source file


information here.

2 In the Type box, enter the format of the file you want to import.
3 Inthe From box, enter the name of the source file.
4 If you selected a spreadsheet in the Type box, enter the sheet number in the Sheet
box that appears.
5 Choose OK.
Visual FoxPro creates a new table using the source file.

If you want to import to a new table from a text file without using the Import Wizard,
you need to create a new table with fields that match the order, data type, and width of
the fields in the text file and then append the text to the new table.
After importing the file, you can add the new table to the database of your choice. For
more information, see Chapter 3, “Collecting Tables into a Database.” You can also
modify the new table using the Table Designer. For more information about modifying
a table, see Chapter 2, “Creating Tables and Indexes.”

Importing from Lotus 1-2-3


When you import spreadsheet data, Visual FoxPro uses the first row in your Lotus 1-
2-3 spreadsheet to determine the data types of the fields in the new table. If the first
row has literal text headings for each column, all the fields in the table will be
character fields, even if the rest of the rows contain numeric data.

> To make sure fields have the appropriate data type


¢ In Lotus 1-2-3, modify the spreadsheet so that the first row contains the first record
of data you want in the table.

User's Guide 153


Part 4 Using Visual FoxPro with Other Applications

Caution If your worksheet is from version 2.x or 3.x (file extension .WK1 or .WK3) and has
columns with more than eight or nine characters, Visual FoxPro truncates character fields to
nine characters for version 2.x worksheets and eight characters for version 3.x. To prevent
truncated fields in your table, you can use the Import Wizard or create a Visual FoxPro table,
then append records from the worksheet.

Lotus stores dates as the non-negative number of days from January 1, 1900. If the
new table does not have the correct data type, you can translate the Lotus date fields in
Visual FoxPro.

Translating Lotus Date Fields


If Lotus date fields imported incorrectly, you can translate them by adding the Julian
date for January 1, 1900 (the value 2415019) to the date value in the field.

> To translate Lotus date fields


1 Import the spreadsheet to a Visual FoxPro table.
2 Use the Table Designer to modify the table and add a new date field to the table.
3 Ifthe date was imported as a numeric value, use the REPLACE command and
CTOD( ) function to copy the date to the new field:
REPLACE ALL NewDateField ;
WITH CTOD(SYS(1@,01dDateField+2415019) )
_—Or-
If the date was imported as a character value, use the following command to copy
the date to the new field:
REPLACE ALL NewField ;
WITH CTOD(SYS(10,VAL(O1dField)+2415019) )
4 From the table, delete the original, incorrect date field.

Importing from Microsoft Excel


When you import worksheet data, Visual FoxPro uses the first row in your Microsoft
Excel worksheet to determine the data types of the fields in the new table. If the first
row has literal text headings for each column, all the fields in the table will be
character fields, even if the rest of the rows contain numeric data.

> To make sure fields have the appropriate data type


¢ In Microsoft Excel, modify the worksheet so that the first row contains the first
record of data you want in the table.

Caution Ifa field in your Microsoft Excel worksheet has a field length of 255, that field is
truncated to 254 when it is imported to a Visual FoxPro table.

154 User's Guide


Chapter 9 Importing and Exporting Data

Appending Data
You can add your text, spreadsheet, or table data to an existing Visual FoxPro table.
By default, Visual FoxPro uses the file type to map the source fields to the destination
table. You can also select fields and records to append. If you want to control the field
mapping, you can use the Import Wizard, but field selection and logical expression
options are not available.

Choosing a File Type to Append


The following table lists the file types you can append to Visual FoxPro.
File Type File Extension Description
Table DBF A FoxPro table from a database outside the
current database or a dBASE file.
Tab delimited IDC A text file with a tab separating each field.
Comma delimited xa A text file with a comma separating each
field.
Space delimited IDG A text file with one space separating each
field.
System Data Format SDF A text file with fixed length records ending
with a carriage return and line feed.
Microsoft Excel XLS A Microsoft Excel (versions 2.0, 3.0, 4.0,
and 5.0) worksheet format. The column
cells become fields and rows become
records.
Lotus 1-2-3 WKS A Lotus 1-2-3 spreadsheet for releases 1-A,
WK1 2.x, and 3.x. The column cells become
WK3 fields and rows become records.
Borland Paradox DB A. Paradox table for versions 3.5 and 4.0.

For more information on appending files, search for APPEND FROM in Help.

Appending Data with the Import Wizard


The Import Wizard asks you a series of questions and appends the data from the
source file based on your answers. Using the wizard, you can choose to map the
source fields to the destination fields by changing the column numbers.

> To append from a file with the Import Wizard


1 From the File menu, choose Import.
2 From the Import dialog box, choose Import Wizard.
3 Follow the instructions on the wizard screens.

User's Guide 155


Part 4 Using Visual FoxPro with Other Applications

Appending Data to an Existing Table


You can add records to the active table from another file. By default, Visual FoxPro
adds all of the records and fields to the table. Using Append From options, you can
specify fields or select records. For more information about field and record selection,
see the sections “Selecting Fields to Append” and “Selecting Records to Append,”
later in this chapter.

> To append data


1 Browse the destination table.
2 From the Table menu, choose Append Records.

Append From dialog box

Enter source file


information here.

Verify the destination


file here. ——to

In the Type box, enter the format of the source file.


In the From box, enter the name of the source file.
In the To box, make sure the correct table name is showing.
Tip Ifthe table name is not correct, choose Cancel, then open the correct destination table.
The To box shows the table active at the time you selected the Append From command.

6 If you want to specify fields or select records to append, choose Options and
complete the Options dialog box.
7 Choose OK.
Visual FoxPro adds the records to the table.

Selecting Fields to Append


You may want to append only certain fields from your source file. You can select the
fields to include in the Append From process.

> To select fields to append


1 From the Table menu, choose Append Records.
2 Inthe Append From dialog box, enter the source file type and name, then choose
Options.

156 User's Guide


Chapter 9 Importing and Exporting Data

Append From Options dialog box

Click here to
select fields.

Click here to enter record selection criteria.

3 In the Append From Options dialog box, choose Fields. The Field Picker dialog
box displays the fields in the destination table.
Field Picker dialog box
Picker

contact
tithe
address
city
region
‘|postalcode

|
Welslslsisishshsiis

4 Select fields that match those you want to append from the source file and choose
move, then choose OK.
The fields you select appear in the Selected Fields box.
5 Choose OK.

Selecting Records to Append


If you only want to append certain records, you can use a FOR expression. Visual
FoxPro uses the expression to search the entire file and append only records that
match the expression you provide. The fields you specify in the FOR expression must
exist in both the source and destination files.

> To select records to append


1 Browse the destination table, then from the Table menu, choose Append Records.
2 Enter the source file type and name, and then choose Options.
3 Choose For to build an expression in the Expression Builder dialog box.
Note You do not need to enter the command FOR because it is implied. For example, type
customer.country = "Canada" to append only Canadian information.

4 Choose OK.

User's Guide 157


Part 4 Using Visual FoxPro with Other Applications

Appending Text Files


If you append from a text file, Visual FoxPro assumes that your fields are separated by
a comma and that each character field is enclosed by quotation marks. If you have set
the decimal point character to display as a comma, numeric and currency data might
be parsed into separate fields.

Appending Numeric or Currency Text


If you changed the Visual FoxPro decimal point character to a comma, numeric and
currency data might be parsed into separate fields when you append or export the
data. For example, Visual FoxPro would translate the value 100,00 into two fields
because it appears to be delimited with a comma. Choose one of two methods to make
sure the comma is properly translated:

¢ Use tabs to separate fields in the text file


¢ Change the decimal point character back to a period

If you want to append from a text file, change the field separators to tabs, then use the
APPEND FROM command with the keywords DELIMITED WITH TAB.
If you want to change the decimal point character to a period before appending text
files, you can change the character back to a comma after you append the file.

> To change the decimal point character


1 In the Command window, type the following command.
SEW POU 1@

2 Import the file using the DELIMITED keyword.


3 In the Command window, type the following command to reset the decimal point
character to a comma.
SEV AROWMT WO“.

Exporting Data
You can export data from your Visual FoxPro tables to text files, spreadsheets, or
tables used in other applications. The exporting process requires a source table and the
destination’s file type and name. If you want, you can select which fields and records
to export. You can use the new file in any application that supports the file type you
select.

158 User's Guide


Chapter 9 Importing and Exporting Data

Choosing a File Type to Export


The following table lists the file types you can export from Visual FoxPro.
File Type File Extension Description
Tabs delimited TXT A text file with a tab separating
each field.
Comma delimited IDSIE A text file with a comma
separating each field.
Spaces delimited IDI A text file with one space
separating each field.
System Data Format SDF A text file with fixed length
records ending with a carriage
return and line feed.
Table DBF A Visual FoxPro, FoxPro,
FoxBASE+e, dBASE, or
Paradox 3.5 or 4.0 table.
Microsoft Excel XLS A Microsoft Excel (versions 2.0,
3.0, 4.0, and 5.0) worksheet
format. The column cells
become fields and rows become
records.
Lotus 1-2-3 WKS A Lotus 1-2-3 spreadsheet for
WK1 releases 1-A, 2.x, and 3.x. The
column cells become fields and
rows become records.

For more information on exporting, search for COPY TO in Help.

Exporting Data to a New File


You can copy all of the fields and records from your Visual FoxPro table to a new file
or you can copy only the fields and records you select.

> To export data


1 From the File menu, choose Export.

Export dialog box

Enter destination file aaa 3.0 (DBF


\
information here.
1 c:\vfp\newtable. dbf

Select the source


file here. —

User's Guide 159


Part 4 Using Visual FoxPro with Other Applications

In the Type box, enter the destination file type.


In the To box, enter the destination file name.
In the From box, enter the source file name.

oa
PP

& If you want to select fields or records to export, choose Options and complete the
Export Options dialog box.
6 Choose OK.

Selecting Fields to Export


By default, Visual FoxPro exports all of the fields in the source table to the destination
file. You can select which fields to export by using the Export Options dialog box.

> To select fields to export


1 From the File menu, choose Export.
Export dialog box
“= Export

Enter destination file 4 Tee -


information here.

Select the source

2 In the Export dialog box, enter the destination file type and name.
3 In the From box, enter the source file name.
4 Choose Options.

Export Options dialog box


Export Opti

Click here to
select fields.

5 Choose Fields and select the fields from the Field Picker dialog box.
6 Choose OK.

160 User's Guide


Chapter 9 Importing and Exporting Data

Selecting Records To Export


When you export data, you might want to limit the number of records that are copied
to the new file by providing selection criteria. You can:
* Choose a scope of records by specifying a quantity or range.
* Build a FOR expression that selects records that match a condition.
¢ Build a WHILE expression that selects records until one record is found that does
not match a condition.

You can use any combination of these options. The WHILE expression overrides the
other criteria.

Exporting a Quantity or Range of Records


One way you can limit the number of records is to specify a quantity or range of
records. Using the Scope option, you can export a single record or a group of records
positioned sequentially in the file.
Note The active index and the current record pointer affect the results of the scope options
Next and Rest. For example, the next record in a table indexed by last name is probably
different than one in a table indexed by state. This does not affect the Record option because
the number for a record does not change when the table is indexed.

> To export a limited number of records


1 From the File menu, choose Export.
2 Enter the source table and destination file information.
3 Choose Options.
Export Options dialog box
Export Options

Click here to
choose records.

Click here to enter criteria for ending record selection.

Click here to enter criteria for record selection.

User's Guide 161


Part 4 Using Visual FoxPro with Other Applications

4 Choose Scope.
Scope dialog box
is Scope

5 Select the appropriate Scope option and complete the Scope dialog box.
To export Choose
Every record from the source file All
A range of records starting with current record Next
A specific record by number Record
The current record plus all of those after it to the end of the file Rest

6 Choose OK.
Visual FoxPro exports records within the scope you select.

Exporting Records That Match a Condition


If the records you want to export are not sequential within the table, you can build a
logical expression that specifies the selection criteria a record must meet to be
exported. For example, you can choose to export all records with a particular value in
a field.

> To enter criteria for exporting records


1 From the File menu, choose Export.
2 Enter the source table and destination file information.
3 Choose Options.
4 Choose For to build an expression in the Expression Builder dialog box.
Note You do not need to include the FOR command in the expression. For example, type
customer.country = "Canada" to export only Canadian data.

5 Choose OK.
Visual FoxPro evaluates all of the records and exports those that match the
condition in the expression.

Controlling the Record Export Process


When exporting, you can specify a condition that must be met to continue evaluating
and selecting records. You enter this condition as a WHILE expression.

162 User's Guide


Chapter 9 Importing and Exporting Data

As long as the WHILE expression remains true, Visual FoxPro processes the source
table. After finding a record that does not meet the condition, Visual FoxPro ends the
evaluation process and exports the selected records. This option allows you to export
records based on information outside of the values contained in the fields.
Tip Ifyou use a WHILE expression on a file that has not been indexed, the export process
may end before evaluating all of the appropriate records. Before performing the export
procedure, be sure the source table has the appropriate index active for the WHILE expression
you want to use.

> To enter criteria for ending record export


1 From the File menu, choose Export.
2 Enter the source table and destination file information.
3 Choose While to build an expression in the Expression Builder dialog box.
Note You do not need to include the WHILE command in the statement. For example, type
sales > 1000 to see only sales above one thousand dollars.

4 Choose OK.
Visual FoxPro exports the records it evaluates while the expression is true.

Exporting Text Files


If you export to a text file, Visual FoxPro assumes that your fields are separated by a
comma and that each character field is enclosed by quotation marks. If you have set
the decimal point character to display as a comma, numeric and currency data might
be parsed into separate fields.
To export to a text file, use the COPY TO command with the appropriate
DELIMITED clause as shown in the following table.
For these separators Use this DELIMITED clause
Commas between fields and quotation DELIMITED
marks enclosing character fields
Character fields enclosed by a character DELIMITED WITH delimiter
other than quotation marks
Tabs between fields DELIMITED WITH TAB
Spaces between the fields DELIMITED WITH BLANK'

1 Date and times separated by a space will be parsed as two fields with these keywords

Exporting Numeric or Currency Values


If you changed the Visual FoxPro decimal point character to a comma, numeric and
currency data might be parsed into separate fields when you append or export the
data. For example, Visual FoxPro would translate the value 100,00 into two fields
because it

User's Guide 163


Part 4 Using Visual FoxPro with Other Applications

appears to be delimited with a comma. Choose one of two methods to make sure the
comma is properly translated:
¢ Use tabs to separate fields in the text file
¢ Change the decimal point character back to a period

If you want to export the text, use the COPY TO command with the keywords
DELIMITED WITH TAB.
If you want to change the decimal point character to a period before exporting text
files, you can change the character back to a comma after you export the file.

> To change the decimal point character


1 In the Command window, type the following command.
SET POINT TO

2 Export the file using the DELIMITED keyword.


3 In the Command window, type the following command to reset the decimal point
character to a comma.
SEM POINT S105

164 User's Guide


CHAPTER 10

Sharing Information with Other


Applications

With Visual FoxPro, you can employ the strengths of other applications by sharing
information with them. You can copy and paste data between applications, create mail
merges using data from Visual FoxPro tables, link or embed data from other
applications, and import or export data between applications. By sharing information,
you can save time and avoid errors. For example, instead of entering results from
Microsoft Excel in a table, you can copy the results from Excel or link to Excel to get
the results automatically.
For details on importing or exporting, see Chapter 9, “Importing and Exporting Data.”
For information about OLE automation, see Chapter 16, “Adding OLE,” in the
Developer ’s Guide.
This chapter discusses:
¢ Sharing Information Quickly
¢ Sharing Information Dynamically

Sharing Information Quickly


You can quickly share data between Visual FoxPro and other applications or data
sources by copying and pasting data. You can also use the Mail Merge Wizard to
expedite mass mailings.

Copying and Pasting Data


If you want to share small amounts of data quickly and easily, but don’t want to share
entire files, select the data manually, cut or copy it, and then paste it wherever you
want it. For example, copy selected data from a form and then paste it into a Word
document, or copy selected cells from a Microsoft Excel worksheet and then paste
them into a General field in a table. You can even copy and paste data into mail
messages and send the messages from within Visual FoxPro.
Tip To share entire files, link or embed them. For details about linking and embedding, see
“Sharing Information Dynamically,” later in this chapter.

User's Guide 165


Part 4 Using Visual FoxPro with Other Applications

> To paste data from another application into a General field


Copy the data to the Clipboard.
2 Open and browse the table containing the General field in which you want to paste
the data.
Double-click the General field.
Embed the data by choosing Paste or Paste Special from the Edit menu.
a fs
Link to the data by choosing Paste Special from the Edit menu and then selecting
Paste Link in the Paste Special dialog box.
Paste Special dialog box

Picture (Metafile)
Picture (DIB)

Tip You can save disk space when linking or embedding by selecting the Display As Icon
check box. When this is selected, Visual FoxPro displays the icon instead of the data.

Creating Mail Merges


A common way of sharing data is to mail letters created from addresses stored in
Visual FoxPro and templates stored in Word. With Visual FoxPro, you can create a
Word document containing data from a Visual FoxPro table by using the Mail Merge
Wizard.

> To use the Mail Merge Wizard


1 From the Tools menu, choose Wizards.
2 From the submenu, choose Mail Merge.
3 Follow the directions in the wizard.

For more information about using the Mail Merge Wizard, search for “Mail Merge
Wizard” in Help.

166 User's Guide


Chapter 10 Sharing Information with Other Applications

Sending Mail from Visual FoxPro


If you have a mail program installed, you can send mail from Visual FoxPro.

> To send mail


¢ From the File menu, choose Send.
Your electronic mail program displays a dialog box in which you can compose and
send a mail message.

You can also send mail from an application by using the MAPI Session Control and
MAPI Messages Control. For more information on these controls, see Help.

Sharing Information Dynamically


In Visual FoxPro, you can dynamically include data from other applications and still
have those applications maintain the data by linking or embedding it in your
application. For example, you can link or embed a Microsoft Word document in a
General field or you can link or embed a Microsoft Excel worksheet on a form.
When you dynamically link data, it is stored in its source file — not in your Visual
FoxPro table or form. The table or form stores only the location of the source and
displays a representation of the linked data. Linked data is updated when the source
file changes and retains a connection to its source file — unless you break the
connection (see “Changing or Breaking Links to Data” later in the chapter).
Note Files with an .AVI extension are always linked.

When you dynamically embed data, it is stored only in your table or form. This data
does not retain a connection to its source file. If changes are made to the source file,
they do not appear in your Visual FoxPro application.

User's Guide 167


Part 4 Using Visual FoxPro with Other Applications

Embedding and linking data

Linked Data

Create links when:


¢ Data or graphics are likely to change
¢ Your application must include the latest version available
¢ The source files are available for updating on your computer or across a network
¢ The source files must be shared with other applications.

Embed data or graphics when:


¢ You don’t need to have the most current versions in your application
¢ The embedded data does not need to be included in more than one application
¢ The source files would not be available for updating if they were linked.

Use the following guidelines to decide on linking or embedding.


To Use this method Details
Create applications you can use on Embed the data. To edit the data, all applications
other computers or edit, even if the from which the data come must
source files are not present. be installed on the computer.
Include data that might not always | Embed the data. All the necessary information is
be available, such as data stored on included with the embedded
a server. data.

168 User's Guide


Chapter 10 Sharing Information with Other Applications

To Use this method Detaiis


Include a very large file, suchasa Create a link to the Your application stores only the
video or sound clip. source file. link, keeping the size of the
application manageable.
Include data that is maintained Create a link to the Your application reflects any
separately in its source application. source application. changes made to the source
application.

The following sections describe how to add data to tables, add data to forms, change
or break links to data, display linked or embedded data from tables, and edit linked or
embedded data.

Inserting Data in Tables


You can include data from other applications in a Visual FoxPro table by inserting the
data into General fields. For example, if you have pictures of products, you can
include them in a table containing other product information by inserting them into a
General field.

> To insert data into a General field


1 Open and browse the appropriate table.
2 Double-click the General field in which you want to insert the data.
3 From the Edit menu, choose Insert Object.
The Insert Object dialog box appears, listing the types of data you can insert into
the field.
Insert Object dialog box
Insert Object

Calendar Control
Media Clip
Mediaview 1.41 Control
Medview Control
Microsoft Excel Chart
MicrosoftExcel Worksheet
Nc &

User's Guide 169


Part 4 Using Visual FoxPro with Other Applications

4 To create data of your own, select Create New and then choose the appropriate
type of data.
Ore
To use existing data, select Create from File. Then, type the name of the file
containing the data, or choose Browse and select the appropriate file. If you want
to link to the file, select Link.

Insert Object dialog box


Insert Object’

Changing or Breaking Links to Data in Tables


After linking to some data, you might want to use a different data source, or you might
want to embed rather than link. To change the data source, you must change the link;
and to embed, you must break the link.

> To change the link to data in a General field


1 Open and browse the appropriate table.
2 Double-click the General field containing the data whose link you want to change.
3 From the Edit menu, choose Links.
The Links dialog box appears.

170 User's Guide


Chapter 10 Sharing Information with Other Applications

Links dialog box

Note Choose Automatic to automatically update data any time it changes in the source
application, or Manual if you want to manually update data.

4 In the Links dialog box, choose Change Source.


The Change Source dialog box appears.

Change Source dialog box


Change Source
es
<4 Samples

{59 Solution
(9 Tastrade

5 Specify the new data source and choose OK.


6 In the Links dialog box, choose Close to complete the change.

> To break a link to data in a General field


1 Open and browse the appropriate table.
2 Double-click the General field containing the data whose link you want to break.
3 From the Edit menu, choose Links.

User's Guide 171


Part 4 Using Visual FoxPro with Other Applications

4 In the Links dialog box, choose Break Link.


5 Choose Close.

When the link is broken, the data becomes static.

Displaying Embedded or Linked Data on Forms


You can enhance the design of forms by linking or embedding data such as Word
documents or Excel worksheets. Similarly, you can enhance reports by displaying
linked or embedded data from General fields. For details, see “Adding a General
Field” in Chapter 7, “Designing Reports and Labels.”

> To link or embed data on a form


1 Create or open a form.
2 On the Form Controls toolbar, select the OLE Container Control button and
drag to size on the form.
The Insert Object dialog box appears, listing the types of files you can link or
embed.
3 Create a new file by selecting Create New.
£Ore
Use an existing file by selecting Create from File. Type the name of the file
containing the data or choose Browse and select the appropriate file. Additionally,
if you want to link to the file, select Link.

Changing or Breaking Links to Data on Forms


You change or break a link to data displayed on a form by using the Links command
on the Edit menu.

> To change a link to data on a form


1 Open the appropriate form.
2 Select the object whose link you want to change.
3 From the Edit menu, choose Links.
4 In the Links dialog box, choose Change Source.
5 In the Change Source dialog box, specify the new data source and choose OK.
6 In the Links dialog box, choose Close to complete the change.

> To break a link to data on a form


1 Open the appropriate form.
2 Select the object whose link you want to break.
3 From the Edit menu, choose Links.

172 User's Guide


Chapter 10 Sharing Information with Other Applications

4 In the Links dialog box, choose Break Link.


5 Choose Close.

When the link is broken, the data becomes static.

Displaying Embedded or Linked Data from Tables


On a form or report, you can display linked or embedded data from General fields in a
table. For example, suppose you have a product table in which each record includes a
General field containing a brochure (a Microsoft Word document) about a product. On
a form, you could display selected information from the records— including the
brochure describing the product.

> To display data from a General field on a form


1 In the Form Designer, add an OLE Bound control to your form.
==]

On the form, Visual FoxPro creates an object through which you can view the data
at run time.
2 Specify the General field that contains the data by setting the object’s
ControlSource property.
For example, if the table name is Inventory and the General field name is
Current, then set the ControlSource property to Inventory.Current.
3 On the form, add buttons or menu commands for browsing the General field
specified in the ControlSource property.

> To display data from a General field on a report


¢ Add a General field to the report.
For details, see “Adding a General Field” in Chapter 7, “Designing Reports and
Labels.”

Including Data in a Report


When creating a report, you can link or embed pictures or icons directly into the
report from an outside source using the image container. Other forms of data, such as
Word documents or Excel spreadsheets, can only be included if they were previously
linked or embedded into a General field in a Visual FoxPro table. For more
information, see Chapter 7, “Designing Reports and Labels.”

Editing OLE Objects in Forms and Tables


You can edit linked or embedded data in a table or form while designing the table or
form. Additionally, you can edit the data in a form while running the form. The
following procedures describe the ways you can edit data.

User's Guide 173


Part 4 Using Visual FoxPro with Other Applications

> To edit data in a General field in a table


1 Open and browse the appropriate table.
2 Go to the record containing the General field you want to edit.
3 Double-click the General field to display the editing window.
4 In the editing window, double-click to edit the data.

To edit embedded or linked objects on a form while designing the form


Select the object representing the data.
With the mouse pointer over the object, click the right mouse button.
VW
=~
on From the shortcut menu, choose the object type, then choose Edit or Open.

> To edit objects or data from General fields on a form while running the form
1 From the Edit menu, select the object.
For example, if the object is a Microsoft Excel worksheet, select Spreadsheet
Object from the Edit menu.
Tip You can also right-click on the object if its AutoVerbMenu property is set to True.
Choose the object type, then choose Edit or Open.

2 To edit the object visually, choose Edit from the submenu.


Ore
To edit the object in a separate window, choose Open from the submenu.

Caution If you change the data in an object while running a form, Visual FoxPro saves the
changes only if the data is linked or is associated with an OLE Bound control. Changes
associated with an OLE Container control are not saved.

174 User's Guide


Chapter 10 Sharing Information with Other Applications

Editing visually

Editing a Microsoft Excel ..merges Microsoft Excel menus with


object on a form... jVisual FoxPro menus in one window.

‘Mict soft Visual FoxPro ‘yf Form Designer - form1.scx - Microsoft Visual FoxPro}
‘Ed = al

[BLUE SKY A SKY AIR!


_ Sales Report
F]
= .
Oe
aE
1 Region
[Sales Report
a North
lg :
Region January February
North eli 13400
South 22100 24050
East 13270 156700
West 10800 21500

If you edit in the Visual FoxPro window, menus from the application you’re using
replace or merge with Visual FoxPro menus. For example, if you’re using Microsoft
Excel, the Excel Edit menu replaces the Visual FoxPro Edit menu. However, the
Visual FoxPro File, Program, and Window menus are not replaced.

Replacing Linked or Embedded Data with Static Data


You can replace linked or embedded data with stand-alone bitmaps by using the
application that created the data.

> To replace linked or embedded data with a bitmap


1 Start the application that created the data by choosing the object containing the
data.
2 In the application, copy the object’s presentation to the Clipboard.
For example, if the application has a Copy Picture command, use it to copy the
object’s presentation.
From the Edit menu in Visual FoxPro, choose Paste Special.
In the Paste Special dialog box, choose Paste Option.
Choose the Picture (Metafile) option.

User's Guide 175


=
45
Pi
_ Repay. rns
“aimsseh tat aSeagirat
Hone ie?plea
“bsg gon SMe Eiht Deswi
ae = menos Aha. Paes ae:

he aay = dy a

& NEY, :

Sit am
> e i ay odemet.wb a
. a
al ay )
_ Spatdgitsit iifGi vest ie
sstiearosh“assent e
Index

Browse
A columns
changing widths 25
Access fields, restricting 29
rearranging 24
Add Join button of Query Designer 90 output option, Query Destination dialog 66
Adjusting control placement 142 windows
Advanced Options dialog 85 Append mode 23
Aggregate functions, grouping query results with 63 changing Browse column widths 25
Aliases, creating for results fields 60 customizing 24
Aligning controls 139, 141 Edit mode 22
AND conditions limiting records in 28
combing with OR conditions 70 rearranging Browse columns 24
setting for queries 68 resizing panes 26
Append mode, Browse window 23 splitting 25
Appending data turning grid lines on and off 25
choosing file types 155 viewing table contents 21
described 155 Browsing tables from Project Manager 9
selecting fields to append 156 Builder button, adding controls to forms with 133
selecting records to append 157 Builder Lock, turning on 134
to existing tables 156 Builders
with the Import Wizard 155 adding controls to forms 133
Applications, sharing information with other 165 Referential Integrity 50
Arranging Tables, customizing the database layout 40 using 14
Ascending sort order 63 Button Lock button, adding multiple controls to forms
with 137

Background colors, setting for forms 145 C


Bands Candidate indexes
changing group in reports 116 controlling entry of duplicate values in fields 35
deleting group in reports 117 described 33
detail See Detail bands Captions, setting field 45
resizing report 105 .CDX (compound structural index) files 31
setting height in reports 120 Character fields, editing 22
summary See Summary bands Circles, adding to reports 123
title See Title bands Colors
Borland Paradox changing control in reports 125
appending data from 155 setting foreground and background for forms 146
importing data from 151 Columns
changing width in Browse windows 25
rearranging in Browse windows 24
Comment box 67

User's Guide 177


Index

Comments D
adding to Data
controls in reports 125 appending 149, 155
queries 67 copying and pasting 165
report controls 110 displaying in forms 129
entering in fields 46 embedded
Compound structural index (.CDX) files 31 displaying from tables 173
Conflicts, update See Update conflicts editing 173
Connection Designer, connecting to remote data replacing with static data 175
with 76 exporting
Connections, creating described 158
described 77 to new files 159
for remote views 78 grouping on report layouts 115
Contents, viewing project with Project Manager 6 importing
Control placement, adjusting 142 and exporting 151
Control source 133 described 150
Controls from Lotus 1-2-3 153
adding multiple 137 from Microsoft Excel 154
adding to forms into new tables 152
described 133, 135-136
with Import Wizard 152
with builders 133 in tables, changing or breaking 170
aligning on forms 139, 141 including in reports 173
coordinates, shown in status bar 142
inserting in General fields 169
copying 139, 141 linked
creating multiple 139
displaying from tables 173
deleting 139, 141
editing 173
mapping fields to 138 replacing with static data 175
modifying tab order 139
linking or embedding
moving 140-141
described 167
placement, adjusting 142
informs 172
report See Report controls
in tables 169
resizing 140-141
ordering
selecting 140
described 35
setting properties 135
using indexes 30
setting tab order
organizing data with data tab 6
by list 143
querying 55
described 142
remote See Remote data
interactively 143
selecting 34
ControlSource property 135
static, replacing linked or embedded data with 175
Coordinates, control shown in status bar 142
updating data with views 73
Copying
updating 79
controls 139, 141
Data entry, controlling 83
report controls 112
Data Environment Designer 135
Cropping pictures in reports 125
Data environments, setting up 135
Currency text
Data placement, planning on reports 104
appending 158
Data sources, setting report 108
exporting 163
Data tab, organizing data with the 6
Cursor output option, Query Destination dialog 66
Data types, choosing 18
Customizing forms 143

178 User's Guide


Index

Database Designer, expanding or collapsing tables Dialog boxes (continued)


in 39 Import 153
Database tables See Tables Insert Object 169
Databases Join Condition 91
adding tables to 41 Links 171
collecting tables into 37 Page Setup 119
contents of 38 Paste Special 166
creating 40 Report Picture 110
defined 6 Report Picture 124
field comments, entering 46 Scope 162
fields View Filed Properties 83
setting captions 46 Work Area Properties 28
setting default values 47 Directing query results 65
opening 39 Display, controlling grid 142
setting field captions 45 Displaying toolbars 12
setting table properties 49 Docking
setting triggers 50 Project Manager 11s
table layout, arranging 40 toolbars 13
tables, finding 42 Documents
using 38 organizing with documents tab 7
views, creating and adding to 41 tab, Project Manager 7
working with 38 Duplicate
Date fields, editing 22 records, eliminating from queries 70
Default field values, setting 47 values, controlling entry in fields 35
Delete Records dialog box 23
Deleting
controls 141
E
Edit mode, Browse window 21
report controls 112
Descending sort order 71 Edit Relationship dialog box 44
Descriptions, adding to files in Project Manager 9 Editing fields 22
Design tools, using Visual FoxPro 12, 17 Eliminating duplicate records from queries 70
Embedded data
Designing
displaying from tables 173
labels See Labels, designing
editing 173
queries 56
replacing with static data 175
reports See Reports, designing
Environment, data See Data environment
Destinations, directing query results with query 65
Exporting data
Detail bands, defining for reports 120
choosing file types 159
Dialog boxes
overview 149, 158
Advanced Options 85
scope 161
Append Form 156
selecting fields to export 160
Append Form Options 157
selecting records 161-162
Change Source 171
selecting records to export 161
Data Grouping 115
Expression Builder, using expressions as a filter 72
Delete Records 24
Edit Relationship 45
Export 159
Export Options 160
Field Picker 106
Go to Record 22

User's Guide 179


Index

Expressions Files (continued)


adding exporting data to new 159
to queries 71 sample 4
to query output 72 Filter tab, Query Designer 61
to remote views 83 Filters
as query filter 72 setting 28
specifying for queries 61, 69
F Find object, finding tables in databases 42
Fonts
Field controls changing in reports 122
adding to reports 110 changing text 144
formatting 120 Footers, page See Page footers
Field properties, setting in databases 47 FOR expression
Fields exporting data with 161
adding selecting records to append 157
to queries 60 selecting records to export 161
to tables 27 Foreground colors, setting for forms 144, 146
captions, setting 45 Form Builder, creating forms with 130-131
control formats, defining 120 Form Designer
controlling data entry 83 creating forms with 129-130
controlling display 83 modifying forms 139
controlling entry of duplicate values 35 saving forms in 132
dragging onto forms 138 Form Designer toolbars 142
editing 22 Form Wizards
entering comments into 46 creating forms with 129-130
inserting data in General fields 169 One-to-Many 130
justifing text in 121 Formats, defining field control 120
making specific updatable 80 Formatting output 120
mapping to controls 138 Forms
ordering by multiple 33 adding controls to
removing from tables 27 described 135
restricting access to 29 with Builders 133
selecting adding graphics to 145
for queries 59 adding lines to 146
to append 156 adding multiple controls at one time 137
to export 160 adding shapes to 144
setting default values for 48 changing or breaking links on 172
updating all 81
changing text fonts on 144
Fields tab, Query Designer 59 creating
File types
described 129
choosing to append 155
with Form Designer 130
choosing to export 159
with Form Wizards 130
import 151
customizing 143
Files
displaying data in 129
adding and removing from projects 8
dragging fields onto 139
adding descriptions to in Project Manager 9
linking or embedding data on 172
adding from one project to another 10
modifying 139
creating and modifying 9
running 132

180 User's Guide


Forms (continued) Index files, compound structural (.CDX) 31
saving 132 Index tab, creating indexes with 31
setting foreground and background colors 145 Index types, choosing 33
Free tables See Tables Indexes
.FRX (Report Layout) files 99 creating 31
Full joins See Joins ordering data using 30
Functions, grouping query results with aggregate 63 ordering records using 31, 32
table, ordering data using 30
G types 33
using to improve performance 34
General fields, editing 22 Inner joins See Joins
Getting started 3
Go to Record dialog 22
Graph output option, Query Destination dialog 66 J
Graphics, adding to forms 145 Join Condition dialog box 90
Grid Join conditions, controlling record selection 89
display, controlling 142 Joins
lines, turning on and off 25 creating by dragging 90
Group bands deleting 91
changing in reports 116 full 90
deleting in reports 117 inner 90
Group By tab, Query Designer 63 left 90
Group/Total Report Wizard 100 modifying 91
Grouping right 90
options, setting for queries 63 Justifying text in fields 122
order, changing in reports 117
query results 62
Groups
K
data See Reports Key fields, setting 80
setting filters 64
L
H Label controls, adding to reports 110
Having button, Query Designer 64 Label Designer, creating mailing labels with 102
Label output option, Query Destination dialog 66
Having option, setting for group 65
Label! Wizard
Headers, page See Page headers
creating mailing labels with 101
Height, setting band in reports 120
described 101
Help, Wizards 13
Labels
designing 97
mailing See Mailing labels
Import file types 153 previewing and printing 125
Import Wizard Layouts, report See Reports, layout
appending data 155 Left joins See Joins
importing data 152 Lines, adding
Importing data to forms 144
described 151 to reports 123
into new tables 152
overview 149
with Import Wizard 152

User's Guide 181


Index

Linked data One-to-Many Report Wizard 100


displaying from tables 173 OR conditions
editing 173 combining with AND conditions 70
replacing with static data 175 setting for queries 69
Links, changing or breaking 170, 172 Order By tab, Query Designer 62
Local tables, creating views of 75 Order, setting for query output fields 60
Logical fields, editing 22 Ordering query results 62
Lotus 1-2-3 Output fields, setting order for queries 59
appending data from 155
exporting data to 159 e-
importing data from 150, 153
Page
footers, defining for reports 120
M headers, defining for reports 101
Mail, sending from Visual FoxPro 167 Pages, defining report 118
Mail Merge Wizard 166 Panes, resizing Browse window 24
Mail merges, creating 166 Parameters
Mailing labels creating views that prompt for 85
creating defined 85
with Label Designer 101 setting up for views 85
with Label Wizard 101 Performance, using indexes to improve 34
layouts, creating 102 Persistent relationships
modifying layouts 103 defined 42
planning data placement 103 described 89
Margins, setting report 119 Pictures
Memo fields, editing 22 adding to reports 126
Microsoft Excel centering in reports 112
appending data from 155 Previewing reports or labels 125
exporting data to 159 Primary indexes
importing data from 151, 154 controlling entry of duplicate values in fields 35
Moving controls 140 described 33
Multiple controls See Controls Printing reports or labels 125-127
Multiple fields, ordering data by 33 Project (.PJX) files 5
Multi-table views See Views Project Manager
Multiuser environment, controlling how update adding and removing files 8
conflicts detected 81 adding descriptions to files 9
adding files from one project to another 10
N creating and modifying files 9
} ; customizing 10
New Report, creating reports with 101 data tabue
Numeric fields, editing 22 design tools 12
Numeric text
docking 11
appending 158
documents tab 7
exporting 163
getting started with 5
introducing 5
0 overview 3
ODBC datasources, connecting to 76 restoring ees pat
On and off, turning grid lines 25 sane Mazards 15
One-to-Many Form Wizard 130 tearing tabs off in 11

182 User's Guide


Index

Project Manager (continued) Query


using Wizards 13 output, adding expressions to 71
viewing project contents 7 results
viewing tables from 9 aggregate functions in 63
Projects grouping 63
adding and removing files 8 ordering 62
adding files from other projects 10 wizards, starting 57
contents, viewing with Project Manager 7 Query Designer
creating and modifying files 9 Add Join button 92
creating new 4 described 56
Properties Destination dialog box 65
setting control 135 Fields tab 59
setting field 45 Filter tab 61
Group By tab 63
Q Having button 64
Order By tab 62
-QPR extension 56 Run button 65
Queries Selected Fields box 60
adding comments to 67 starting 57
adding expressions to 71 window, displaying 58
adding fields to 60 Query Destination, directing query results with 65
adding views and tables 88 Querying data, overview 55
aggregate functions in query results 63 Quick Form command
AND conditions, setting 68 creating forms with 129
creating with wizards 57 described 130
customizing 68 Quick Reports, creating 105
designing 56
Destination dialog box 65
directing results 65
eliminating duplicate records 70 Record order, setting with indexes 31
expressions as filter 72 Records
filter adding to tables 20, 23
described 68 deleting 23
specifying 61 eliminating duplicates from queries 70
grouping options, setting 64 filtering 34
grouping results 63 limiting in Browse windows 28
Having option, setting for group 65 ordering
multiple table 87 described 35
multiple views 87 using indexes, overview 30
ordering results 62 selecting
results fields, creating aliases for 60 described 34, 61
running 65 to append 157
selecting desired records 61 to export 161-162
selecting fields for 59 Rectangles, adding to reports 122
setting group a filter 64 Referential integrity, managing records 50
setting OR conditions 69 Referential Integrity Builder 50
setting order for output fields 60 Regular indexes 33
viewing SQL statements 67

User's Guide 183


Index

Relationships Reports (continued)


creating between tables 42 deleting group bands 118
persistent See Persistent relationships designing 97
Remote data field control formats, defining 121
connecting to 76 formatting field controls 121
creating connections 77 grouping data on layouts 114
viewing and updating 76 grouping order, changing 117
Remote View Wizard, creating views with 74 including data in 173
Remote views justifying text in fields 121
adding expressions to 83 layout files 99
creating 78 layout Wizards 101
Report controls layout, determining the general 98
adding comments to in reports 110, 125 lines, rectangles and circles, adding to 123
adjusting placement 111 mailing label layouts, creating 101
aligning 112 margins, setting 119
copying and deleting 112 modifying bands 105
inserting 105 page headers, defining 121
resizing 111 planning data placement 103
selecting and moving 111 previewing and printing 125
Report layout (.FRX) files 99 printing 126
Report output option, Query Destination dialog 66 report controls
Report Wizard copying and deleting 113
creating reports with 100 inserting 105
described 100 report pages, defining 118
Report Writer, creating Quick Reports 105 setting band height 121
Reports setting data sources 107
adding comments to controls 125 summary bands 120
adding field controls 109 Resizing
adding general data fields to 111 controls 139-140
adding label controlss 109 report controls 111
adding multiple data groupings 115 Results fields, creating aliases for 60
adding pictures to 124 Right joins See Joins
adding single group 115 Run button, Query Designer 65
adding title bands 124 Run Form command 132
adjusting control placement 113 Running forms 132
aligning controls 112
centering pictures in 124 S
changing control colors 125
changing fonts 122 Sample files 4
changing group bands 116 Saving forms 132
controls See Report controls Screen output option, Query Destination dialog 66
creating .SCX extension 132
with New Report 97 Selected Fields box, Query Designer 60
with Report Wizard 100 Selecting controls 138
creating blank 101 Setting tab order for controls
creating layouts 101 by list 143
cropping pictures in 125 described 142
customizing layouts 119 interactively 143
defining detail bands 121

184 User's Guide


Index

Shapes, adding to forms 144 Tables (continued)


Sort order creating (continued)
ascending 71 with Table Designer 19
descending 71 with Table Wizard 18
Sort order, setting with Order By tab, Query customizing 28
Designer 62 database vs. free 21
Source, Control 133 displaying embedded data from 173
Spreadsheets displaying linked data from 173
appending data to 156 expanding or collapsing 39
exporting to 158 exporting to 158
importing from 151 filtering 28
SQL DELETE 84 finding 42
SQL INSERT 84 importing 151
SQL statements, viewing query 67 importing data into 152
SQL UPDATE 84 indexes, ordering data using 30
SQL WHERE 81 joining
Static data, replacing linked or embedded data with 175 for queries 88
Status bar, showing control coordinates in 142 in views 91
Summary bands, adding to reports 120 linking or embedding data in 168
making specific fields updatable 80
+ making updatable 79
multiple
Tab order in views 91
control 142 quering and updating 87
setting remote in views 92
by list for controls 143 navigating within 22
for controls 142 persistent relationships 89
interactively for controls 143 querying multiple 87
Table Designer, creating tables with 19 removing fields from 27
Table output option, Query Destination dialog 66 resizing in Database Designer 39
Table Wizard, creating tables with 18 setting properties for 47
Tables setting triggers 50
adding setting validation rules 47
to databases 41 storing information in 20
to queries 88 structures, modifying 26
adding fields to 27 updating multiple 87
adding records to 23 updating 79
appending data to existing 156 using 17
arranging in a database 40 viewing from Project Manager 9
browsing viewing information in 20
described 21 Tabs
from Project Manager 7 restoring in Project Manager 11
changing or breaking links to data in 170 tearing off in Project Manager 11
collecting into databases 37 Text data, appending 158
creating Text files
described 17 appending data to 156
overview 17 appending 155
relationships between 42 exporting to 158

User's Guide 185


Index

Text files (continued) Views (continued)


exporting 163 multiple remote tables in 92
importing 151 multiple tables in 91
Text fonts, changing on forms 144 multi-table, defining 91
Text sizes, changing on forms 144 persistent relationships 89
Text, justifying in fields 122 querying multiple 87
Timeout intervals, setting 85 remote
Title bands, adding to reports 120 adding expressions to 83
Toolbars creating 78
displaying 12 setting up parameters for 84
docking 13 usefulness of 73
Form Designer 141 Visual FoxPro
using 12 getting started 3
Triggers, setting 50 sending mail from 167

U W
Unique indexes 36 WHILE expression
Updatable exporting data with 158
making specific fields in tables 80 selecting record to export 160
making tables 79 Wizards
Update conflicts, controlling how detected 81 creating queries with 56
Update Criteria tab, View Designer 79-80 Help on 13
Update method, controlling the 84 Query, See also Query Wizards
Remote View 74
V Report Layout 101
starting 13
Validation rules using 13
setting for tables 49 View 74
setting 49 Work Area Properties dialog box, setting filters in 28
Validation text, setting 47
Values, creating views that prompt for 85
View Designer
creating view with 75
setting key fields 80
Update Criteria tab 79
View SOL 67
View Wizard, creating views with 74
Views
adding to queries 88
Advanced Options dialog 86
creating
and adding 41
described 73
that prompt for values 85
with Wizards 74
customizing 82
joining tables in 91
local tables, creating 75

186 User's Guide


\ «
; ; re ae,

a ae“yy ja

» fod! Ge skeen os t
a e ee
ewe aultiple Wi?
Fer? én ‘ :
7 7 - => »

Uaaw shes} mw ar * CP as an 5 AN.


ey ek ar we . my ~~ po eeeenenng a
a ae” a
mith TS: a a
Ss
a ——
ae Oe Pet eee te = 5
Sebey a aes a

3 acuta Sass,tle Ee. :


a \ gimhug
es? espe ie
Ge 4

~e 2 i o ;
~~ es
™~,, ~ Se | catatiens nah |<
Sagattree _— 7.

~~ @

ad xa 4
ee ae es 2
terme — ;
> ihn 2 oes
ats 4
i oeof
Sel, | 7 1 7 its
- : 7
£ 4 . ' ) > P.

Wes
my
— ay + Eve
a .
= ool
Pa

: ; s
Wiig :- Z “*6 May ty
aire - Us a ;
an . =
ineohy, a . fa
it g a i =

Ta) iy

ear
if Q a

2 ounce
a

~
The Visual FoxPro Standard Toolbar

1@) Xs SS a) 9 9
~
SF WEP S Me™ Wee

See all files at once. ——? Ail” 1121’ See menus and
See all databases, free : text files.
queries, and views.
fA Ete
See all forms, ay
reports, and labels. ——= dorama Views Buttons
»@®_= Connections
(2) Stored Procedures
» EE] Free Tables
Track files by adding | _-t& Queries
descriptions that ‘1 2/1 Oscunents
display here. ——_!pescriation:
See programs
File location _ Trai Z and classes.

The items in the Project Manager are organized in an outline view that you can expand or collapse to see different levels
of detail. You can also customize the appearance of the Project Manager to match the way you like to work.

Project Manager - Project!


a -}- Click her
Click here to keep a tab _ Dec e to collapse
on top of other windows. ——— or expand the Project
| pao Manager.
Click here to expand or Click here to return
collapse an item. | a tab to the Project
aireEA) @ customer
SEB) © employee Manager.
mee Drag tabs to move them
Queries away from the Project
Manager.

ee es Micresoft

You might also like