4D v13.4

ADD RECORD

Home

 
4D v13.4
ADD RECORD

ADD RECORD 


 

ADD RECORD ( {aTable}{;}{*} ) 
aTable  Table in Table to use for data entry, or Default table, if omitted
in Hide scroll bars

The ADD RECORD command lets the user add a new record to the database for the table aTable or for the default table, if you omit the aTable parameter.

ADD RECORD creates a new record, makes the new record the current record for the current process, and displays the current input form. In the Application environment, after the user has accepted the new record, the new record is the only record in the current selection.

The following figure shows a typical data entry form.

The form is displayed in the frontmost window of the process. The window has scroll bars and a size box. Specifying the optional * parameter causes the window to be drawn without scroll bars or a size box.

ADD RECORD displays the form until the user accepts or cancels the record. If the user is adding several records, the command must be executed once for each new record.

The record is saved (accepted) if the user clicks an Accept button or presses the Enter key (numeric keypad), or if the ACCEPT command is executed.

The record is not saved (canceled) if the user clicks a Cancel button or presses the cancel key combination (Ctrl-Period on Windows, Command-Period on Macintosh), or if the CANCEL command is executed.

After a call to ADD RECORD, OK is set to 1 if the record is accepted, to 0 if canceled.

Note: Even when canceled, the record remains in memory and can be saved if SAVE RECORD is executed before the current record pointer is changed.

The following example is a loop commonly used to add new records to a database:

 FORM SET INPUT([Customers];"Std Input") ` Set input form for [Customers] table
 Repeat ` Loop until the user cancels
    ADD RECORD([Customers];*) ` Add a record to the [Customers] table
 Until(OK=0) ` Until the user cancels

The following example queries the database for a customer. Depending on the results of the search, one of two things may happen. If no customer is found, then the user is allowed to add a new customer with ADD RECORD. If at least one customer is found, the user is presented with the first record found, which can be modified with MODIFY RECORD:

 READ WRITE([Customers])
 FORM SET INPUT([Customers];"Input") ` Set the input form
 vlCustNum:=Num(Request("Enter Customer Number:")) ` Get the customer number
 If(OK=1)
    QUERY([Customers];[Customers]CustNo=vlCustNum) ` Look for the customer
    If(Records in selection([Customers])=0) ` If no customer is found…
       ADD RECORD([Customers]` Add a new customer
    Else
       If(Not(Locked([Customers])))
          MODIFY RECORD([Customers]` Modify the record
          UNLOAD RECORD([Customers])
       Else
          ALERT("The record is currently being used.")
       End if
    End if
 End if

Accepting the record sets the OK system variable to 1; canceling it sets the OK system variable to 0. The OK system variable is set only after the record is accepted or canceled.

 
PROPERTIES 

Product: 4D
Theme: Data Entry
Number: 56

The OK variable is changed by the commandThis command changes the currrent recordThe command changes the current selectionNot for server

 
INDEX

Alphabetical list of commands

 
HISTORY 

Created: < 4D v6

 
SEE ALSO 

ACCEPT
CANCEL
CREATE RECORD
MODIFY RECORD
SAVE RECORD