ADD RECORD

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 3


ADD RECORD ({table}{; }{*})

ParameterTypeDescription
tableTableTable to use for data entry, or
Default table, if omitted
*Hide scroll bars

Description

The ADD RECORD command lets the user add a new record to the database for the table table or for the default table, if you omit the table 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 Custom Menus 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.

Examples

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

   INPUT FORM ([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

2. 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])
   INPUT FORM([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

See Also

ACCEPT, CANCEL, CREATE RECORD, MODIFY RECORD, SAVE RECORD.

System Variables or Sets

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.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next