BeforeAddTable, AfterAddTable, BeforeCreateTable, AfterCreateTable

These database events fire when an existing free table is added to a database (the Add events) or when a new table is created (the Create events).

Usage

PROCEDURE DBC_BeforeAddTable( cTableName, cLongTableName )
 
PROCEDURE DBC_AfterAddTable( cTableName, cLongTableName )
 
PROCEDURE DBC_BeforeCreateTable( cTableName, cLongTableName )
 
PROCEDURE DBC_AfterCreateTable( cTableName, cLongTableName )

Parameter

Value

Meaning

cTableName

Character

The name and full path of the DBF file.

cLongTableName

Character

The long name of the table.


Several commands can create a table that belongs to a database: COPY STRUCTURE, COPY TO, CREATE FROM, and IMPORT, when the DATABASE clause is specified; CREATE when a database is selected; and CREATE TABLE when a database is selected and the FREE clause isn't specified. Interestingly, though, the first set of commands fires the Add rather than Create database events; it appears as though VFP creates a free table first, and then adds it to the database. As you'd expect, ADD TABLE fires the Add events. The Create and Add events are also fired when you create or add a table from the menu in the Database Designer.

AfterCreateTable is passed the wrong value for the cLongTableName parameter when a table is created visually (that is, in the Table Designer) and the long name is changed from its default value. Although the new long name is correctly stored, cLongTableName receives the original value.


You can prevent a table from being added or created by returning .F. in the Before events, while the After events simply receive notification that a table was added or created. This is true for all sets of before-and-after database events.

Example

* This goes in the stored procedures of the database.
 
PROCEDURE DBC_BeforeAddTable(cTableName, cLongTableName)
WAIT WINDOW PROGRAM() + CHR(13) + ;
    "cTableName=" + cTableName + CHR(13) + ;
    "cLongTableName=" + cLongTableName
 
PROCEDURE DBC_AfterAddTable(cTableName, cLongTableName)
WAIT WINDOW PROGRAM() + CHR(13) + ;
    "cTableName=" + cTableName + CHR(13) + ;
    "cLongTableName=" + cLongTableName
 
PROCEDURE DBC_BeforeCreateTable(cTableName, cLongTableName)
WAIT WINDOW PROGRAM() + CHR(13) + ;
    "cTableName=" + cTableName + CHR(13) + ;
    "cLongTableName=" + cLongTableName
 
PROCEDURE DBC_AfterCreateTable(cTableName, cLongTableName)
WAIT WINDOW PROGRAM() + CHR(13) + ;
    "cTableName=" + cTableName + CHR(13) + ;
    "cLongTableName=" + cLongTableName
 
* End of stored procedures.
 
 
* Open the database and turn on DBC events.
 
OPEN DATABASE TestData
DBSetProp('TestData', 'Database', 'DBCEvents', .T.)
 
* Create a table in the Table Designer.
 
CREATE TestTable
 
* Create a table programmatically.
 
CREATE TABLE TestTable2 NAME "My Long Table Name" ;
    (FIELD1 C(10))
 
* Create a free table, and then add it to the database.
 
CREATE TABLE TestTable3 FREE (FIELD1 C(10))
USE
ADD TABLE TestTable3 NAME "Another Long Name"

See Also

Add Table, BeforeCreateView, Copy Structure, Copy To, Create, Create From, Create Table, Database Events, Import


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .