Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Automated Transaction number
Message
De
16/03/2006 19:22:47
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
16/03/2006 19:18:03
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP1
Database:
Visual FoxPro
Divers
Thread ID:
01105154
Message ID:
01105155
Vues:
19
>Sir excuse me.. (sorry guys , i'm just a student here) I have a table with Transaction number. In my form I want to have that transaction number automatically adds up by 1 whenever I press the New Record button. What commands will I put before the Append Blank. The table and the fields are tblTransaction.transno . Hope you could help me with this . Sorry if I disturb you all..

I am including the function I use.

For primary keys which the user doesn't see, you can invoke it from a field's default value.

For fields which the user sees, this can result in values being skipped (if the user cancels the record, the number will not be assigned again). In this case, better assign the number only when the user saves the record.

HTH,

Hilmar.
**********************************************************************
FUNCTION SerialNumber(tcSequence)
	* Get serial number. Used mainly to generate primary keys.
	* The easiest way to achieve this is to call this function from a fields default value.
	* Example: default value for primary key "Client" of table "Client" = SerialNumber("Client")
	* This function accesses table SerialNumber. Fields: Sequence C(30), NextNum I.
	tcSequence = lower(tcSequence)
	local lnSelect
	lnSelect = select()
	if used("serialnumber")
		select serialnumber
	else
		select 0
		use serialnumber
	endif
	set order to "sequence"
	seek padr(tcSequence, len(sequence))
	if not found()
		append blank
		replace sequence with tcSequence, nextnum with 1
	endif
	local lnReturnValue
	if lock()
		lnReturnValue = nextnum
		replace nextnum with nextnum + 1
	else
		lnReturnValue = -1
	endif
	unlock
	select (lnSelect)
	return lnReturnValue
ENDFUNC
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform