Visual FoxPro Users Guide -- Microsoft -- ( WeLib.org )
Visual FoxPro Users Guide -- Microsoft -- ( WeLib.org )
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
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.
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.
Introduction xi
About This Book xi
Getting Help xiii
Need Help? Press Fl xiii
Sample Files xiii
Document Conversions xiil
iv User’s Guide
Contents
User’s Guide v
Contents
vi User’s Guide
Contents
User’s Guide ix
Contents
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.
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.
Getting Help
The Visual FoxPro Help system gives you quick access to information about using the
Visual FoxPro design tools and language elements.
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.
~~ : 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,
=
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
User's Guide 1
7 TARAS
fortsmotal onixiag
b abinsd eraaty
CHAPTER 1
Getting Started
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
Project Manager
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 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.
The Project Manager is your “control center” for working with Visual FoxPro.
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
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
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.
User’s Guide 7
Part 1 Organizing Information
To collapse a list once it is expanded, click the minus sign that appears next to the list.
If you want to delete the file from your computer, choose Delete.
8 User’s Guide
Chapter 1 Getting Started
With some items, you have the option to use a wizard to help you create the file.
For example, to modify a table, select the name of the table and choose Modify to
display the table in the Table Designer.
User’s Guide 9
Part 1 Organizing Information
You can easily return the Project Manager to its usual size.
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.
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.
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.
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.
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.
12 User’s Guide
Chapter 1 Getting Started
2 Inthe Toolbars dialog box, select the toolbars you want to use.
3 Choose OK.
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.
You can also access most wizards directly by choosing the Wizards command from
the Tools menu.
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.
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.
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
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
e- & WAide:
ea tcorilen 3FN et eee telected wens §esheets
4 le ——.
a
lanes ane & pass Ree seen ee es
_ ‘.
adWanciaigitma)
. han - tes te bin ih Hae
in al ste ute ithhon Been, gna
aCe”. “ Seca paar
CHAP
1 ER 2
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.
User’s Guide 17
Part 1 Organizing Information
¢ 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.
18 User's Guide
Chapter 2 Creating Tables and Indexes
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.
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.”
User’s Guide 19
Part 1 Organizing Information
t /customer_id Character
company_name Character
contact_name Character 30
/] contact_title Character 40
4 address Character 60
: city Character
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.
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.
Each row is a
database record.
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
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.
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
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.
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.
gy Customer
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.
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.
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.
¢ 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
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
User’s Guide 25
Part 1 Organizing Information
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
company_name Character
{ contact_name Character
Character
Character
Character
‘Customer ID
Customer ID
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.
¢ 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"
TEES
= EN S
d Market
User’s Guide 29
Part 1 Organizing Information
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.
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
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.
User’s Guide 31
Part 1 Organizing Information
Once you create an index for the table, you can use it to order your records.
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.
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.”
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.
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
Data Entry
FE ~
EnteranID for the customer: VAF The value entered...
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
36 User’s Guide
CHAPTER 3
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
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
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.
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
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.
User’s Guide 39
Part 1 Organizing Information
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.
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
You can remove a table from a database if it is no longer needed, or if you need to use
it in another database.
User’s Guide 41
Part 1 Organizing Information
If you want to show only the tables or only certain views, you can choose to display
only tables or certain views.
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.
42 User’s Guide
Chapter 3 Collecting Tables into a Database
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.
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.
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.
-Datal
ytdpurch
lat
lona
cng
CAlindexes:
44 User’s Guide
Chapter 3 Collecting Tables into a Database
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.
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.
freds Futterkiste
46 User’s Guide
Chapter 3 Collecting Tables into a Database
For example, you might want all new records in a Products table to have a default
“reorder at” setting of 15 units.
it_cost 26.3500
/) |Prod_namelkura
| |Eng_name Fish Roe
| |No_in_unit 12 - 200 mil jars
31.000
| |Reorder_at15.000
Discontinu F
User’s Guide 47
Part 1 Organizing Information
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.
Revat |
48 User’s Guide
Chapter 3 Collecting Tables into a Database
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.)
User’s Guide 49
Part 1 Organizing Information
4IIFfCustom
: Ss Validation rule and error
2 [Orde from WA, stat message for table.
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.
50 User’s Guide
Chapter 3 Collecting Tables into a Database
User’s Guide 51
ie eee oe a
rmHh apa
aD agegat
- ise ae Steak and ) eae enn
am en ri
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.
User's Guide 53
, %
‘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.
¢ Highest sales?
“2 __ Best Customers in Region?
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.
You can also choose Wizards on the Tools menu to start a wizard.
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
After you select a table or view, Visual FoxPro displays the Query Designer window.
Employee
last_name
first_name
title
bith_date
58 User’s Guide
Chapter 4 Retrieving Data
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.
shefe
Employee.emp
ig
nplayee. jast_name
Employee first_narme
— {Employee title
~ {Employee. birth_date
. Employee. hire_date
User’s Guide 59
Part 2. Finding Information
ployee.emp_id
Empl a
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
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.
User’s Guide 61
Part 2 Finding Information
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.
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.
ae :
ustomer.cust_id
ustomer.company ‘ : With the criteria
in this order...
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.
User’s Guide 63
Part 2 Finding Information
__|Cust_id| Sum_order_net |
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
id| Sum_order_net _
113683.7570
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.
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.
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
User’s Guide 67
Part 2 Finding Information
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.
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
re “Walla Walla
a F 4
eattle
User’s Guide 69
Part 2 Finding Information
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.
Customer.region
Customer.maxordamt
Customer.region
Customer.maxordamt <None>
ountry Store
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.
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.
Note Null values are ignored in calculations. For more information on null values in
expressions, search for “Null Values” in Help.
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
This expression
multiplies the values
of two fields.
_ {ship_count
ship_via
A_|marain
| padvance
4_Pageno
= SK yy x / |_pbpage
72 User’s Guide
CHAPTER 5
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
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.
74 User’s Guide
Chapter 5 Updating Data with Views
EB Databases
FH @ testdata
ith Tables
ocal Views
>» @ Remote Views
> Connections
fF} Stored Procedures
i Free Tables
‘ Queries
¥) j=) Documents
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 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.”
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.
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.
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.
78 User’s Guide
Chapter 5 Updating Data with Views
uthors.au_lIname
uthors.au_fname
uthors.telephone
uthors.address
uthors. city
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.
User’s Guide 79
Part 2 Finding Information
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.
80 User’s Guide
Chapter 5 Updating Data with Views
group
indent
text
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.
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.
82 User’s Guide
Chapter 5 Updating Data with Views
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.
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.
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.
When you use the view, a message box appears prompting for a value to include in the
filter.
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.
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
i a ‘ Se
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 :
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
User's Guide 87
Part 2 Finding Information
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.
88 User's Guide
Chapter 6 Querying and Updating Multiple Tables
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.
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.
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 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.
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.
For more information about logical operators used in join criteria, search for “Logical
Operators” in Help.
User's Guide 91
Part 2 Finding Information
cust_id
| company
contact
title
Customer.company
Customer.contact
Customer. title
Customer. address
Customer. city
Customer.region
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.
92 User's Guide
Chapter 6 Querying and Updating Multiple Tables
‘Authors. au_fname
Authors.telephone
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.
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.
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.
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
User's Guide 95
enin gi se:
(helene iMy
uo
rie
a
any
ys ‘
CHAPTER 7
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:
User's Guide 97
Part 3 Displaying Information
Decide the
general layout
sport Design
NS
y oa gor
Lees: : = Sf:
contact. = pas od cae
Customize the
layout
98 User's Guide
Chapter 7 Designing Reports and Labels
e 7 ae
a
ES
SSAA
SRE
ee
wai oO
co
—
A
OSES
SOIC
ARERR
Seem a
eae
aiaeaamareocnneee
meNESRRRERHEE
ANAT
SRR
a
ETERS
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
After you select the general report layout that meets your needs, you can create the
report layout file with the Report Designer.
User's Guide 99
Part 3 Displaying Information
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.
The wizard you choose depends on the general layout and complexity of your report.
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.
You can use any of the Report Designer features to add controls and customize your
report.
You can use the label layout as it is or customize it using any of the features described
for reports.
Standard label paper choices appear in the New Label dialog box
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.
You can open your report or label in the Report Designer to modify and customize the
layout.
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.
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.
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.
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.
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.
For more information about the options in the Quick Report dialog box, see Help.
Field layout:
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.
Selected fields
C
Cc
fe
c
E;
c
Cc
[=
8 Choose OK.
<
Maneatis aioAge acircotates + |ny
Harvey Whitcomb | 19 Wa" i “<
Vivian Zimmer i
company_na
contact_na
contact_ti
a a
You can set the order your records appear in your report by setting an index for the
data environment.
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.
For more information about integrating queries and other data sources, see Chapter
12, “Adding Queries and Reports,” in the Developer’s Guide.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Enter an expression.
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.
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.
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.
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.
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.
For information about adding columns to your report page, see Chapter 12, “Adding
Queries and Reports,” in the Developer’s Guide.
CABELL
LSD DMR ELLY
Set the left margin 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.
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.
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.
Select field
control formatting
options here.
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.
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.
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.
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.
—1c\vip\samples‘\mainsamp\bitmay
z SENS
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
Report Preview
Previous page Next page
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
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.
7 j 2 — . re -
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
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.
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.
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.
The Form Designer window appears so you can begin creating your form.
The Form Builder helps you quickly create a form from a table or view.
‘sf Form Builder
No_in_unit
Unit_price
_ {Unit_cost
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.
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.
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.
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.
Tip Use ToolTips on the Form Controls toolbar to help you identify class names.
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.
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.
emp_id
last_name
first_name
title
birth_date
Note To add views to the Data Environment Designer, you must have a database open.
Note If you want to use the Properties window to set control properties, make sure Builder
Lock is turned off.
employee. hire_date
employee. address
When you drag a field or table onto a form, Visual FoxPro determines what type of
control to create based on options you set.
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.
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.
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.
2 Drag one of the sizing handles to increase the length, width, or overall size of the
control.
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.
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.
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.
Using the Form Designer, you can customize your forms by:
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.
You can change the type of shape drawn with the Curvature property in the Properties
window.
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.
Tip If you select None, the Form Designer will not impose a limit on the size of form you can
design.
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
~
“~~
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
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.”
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.
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.
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.
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.”
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.
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.
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.
For more information on appending files, search for APPEND FROM in Help.
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.
Click here to
select fields.
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.
4 Choose OK.
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.
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.
oa
PP
G®
& If you want to select fields or records to export, choose Options and complete the
Export Options dialog box.
6 Choose OK.
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.
Click here to
select fields.
5 Choose Fields and select the fields from the Field Picker dialog box.
6 Choose OK.
You can use any combination of these options. The WHILE expression overrides the
other criteria.
Click here to
choose records.
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.
5 Choose OK.
Visual FoxPro evaluates all of the records and exports those that match the
condition in the expression.
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.
4 Choose OK.
Visual FoxPro exports the records it evaluates while the expression is true.
1 Date and times separated by a space will be parsed as two fields with these keywords
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.
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
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.
For more information about using the Mail Merge Wizard, search for “Mail Merge
Wizard” in Help.
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.
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.
Linked Data
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.
Calendar Control
Media Clip
Mediaview 1.41 Control
Medview Control
Microsoft Excel Chart
MicrosoftExcel Worksheet
Nc &
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.
Note Choose Automatic to automatically update data any time it changes in the source
application, or Manual if you want to manually update data.
{59 Solution
(9 Tastrade
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 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.
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.
Editing visually
‘Mict soft Visual FoxPro ‘yf Form Designer - form1.scx - Microsoft Visual FoxPro}
‘Ed = al
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.
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
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
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
a ae“yy ja
» fod! Ge skeen os t
a e ee
ewe aultiple Wi?
Fer? én ‘ :
7 7 - => »
~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.
ee es Micresoft