PawCom Application Note 106: Unique Journal Keys ================================================ When Peachtree designed the file structure for the Journal file JrnlHdr.dat they specified that certain fields in the records must be unique. If you attempt to insert a new journal record with an existing value for any of these fields you will get a Btrieve error 5: Duplicate Key Value. Although it is possible to define a unique key value to be autogenerating in Btrieve so that a value of 0 will automatically cause Btrieve to generate a new value on an insert, none of the keys for the journal files have been defined that way. This means that you must generate the unique values yourself. The unique JrnlHdr keys are: JrnlHdr: NRecord, (JournalID,Period,TrxNumberL,Subindex1,Subindex2), GUID NRecord is a unique number for every JrnlHdr transaction independent of the kind of journal entry. Although there is no requirement for this number to be sequential for each new journal transaction, Peachtree always seems to generate new transactions that way. Since transactions can be entered for different kinds of journals in any order, the subsequent NRecord numbers for a particular journal will not necessarily be in sequential order but will have gaps where the intermediate NRecord numbers were used for other types of journals. The various journal classes and the JrnlHdr class in PawCom have a property MaxNRecord that returns the largest NRecord number currently assigned. YOu can use this value + 1 to specify the NRecord number for a new transaction. The set of fields (JournalID,Period,TrxNumberL,Subindex1,Subindex2) must be unique, meaning that the set of five values must not duplicate the values for an existing record. However, Btrieve does not have any restrictions beyond this about the actual values used for the individual fields. JournalID is an integer code for the type of journal transaction: General = 0 Cash Receipts = 1 Cash Disbursements = 2 Sales = 3 Purchase = 4 Payroll = 5 Inventory Adjusment = 7 Assembly Adjustment = 8 Purchase Order = 10 Sales Order = 11 Quote = 12 Subindex1 and Subindex2 are normally 0, but may have a value of 1 or 2 for special kinds of transactions described in Chapter 4 of the PawCom manual. Period is an internal period number (see Application Note 101). The function mwPeriodForDate in the module Support functions of the PawCom Access application will compute the correct period for you based on the date. TrxNumberL is a running counter for a given journal and period. Each of the journal classes and the JrnlHdr class have a property MaxTrxNumberL that will determine the maximum TrxNumber in use for the specified journal and period. You can use this value + 1 for the TrxNumberL value for the next transaction for a specific journal. GUID was added to the JrnlHdr records with Peachtree V10 (2003) but wasn't made a unique key unti V11 (2004). A GUID is a universally unique identifier that Microsoft generates by some unknown algorithm. The PawCom class Peachw has a GUID property that will return a new GUID that you may use for new V11 or later JrnlHdr records. Up until recently the JrnlRow.dat records did not have any unique keys. However, the combination of NRecord, LineNo and TrxType should always be unique to keep Peachtree happy. Starting with the 2004 Manufacturing and Distribution versions and for all later versions of Peachtreee the field UMGUID must be unique if it is specified.