>Thanks Hilmar!!!
>I did have an add button that will double as a save button. So the Code looks like this:
>
>DO CASE
> CASE ALLTRIM(UPPER(This.Command5.CAPTION)) = 'Add'
> SELECT PAID_TOB
> SET ORDER TO PAID_ID
> APPEND BLANK
> THISFORM.REFRESH()
> THIS.COMMAND5.CAPTION = 'Save'
> CASE ALLTRIM(UPPER(THIS.COMMAND5.CAPTION)) = 'SAVE'
> BEGIN TRANSACTION
> REPLACE ENTEREDBY WITH ALLTRIM(SYS(0)) +' '+ALLTRIM(GETENV('USER')) ;
> ENTERDATE WITH DATETIME()
> REPLACE PAID_ID WITH GETKEY('PAID_TOB')
> IF TABLEUPDATE()
> END TRANSACTION
> ELSE
> ROLLBACK
> MESSAGEBOX('This Record could not be added',64,'Error Adding Record')
> ENDIF
> THIS.COMMAND5.CAPTION = 'Add'
>ENDCASE
>
>also in the
GETKEY() function, I changed the
if Found() to
IF SEEK(alltrim(upper(tcTable)) >For Some odd reason the Found would not go into the if statement, but the Seek() would.
>Go figure :-)
>
>Now I will try to do this on multiple sessions and see if it works
>Thanks Again
>
Hello Leroy,
PMFJI...
Do you use the same button when saving a record that someone is editing? If so, you have a problem...the primary key would change every time someone edits and saves a record.
Also, if you use this logic in a 2 level form (such as an invoice header with line items), you don't have the primary key until the user saves the header. You may need to know the primary key earlier, so you can use that as a field in the child records (the invoice line items).
Assigning the primary key field value by in the default of a field allows VFP to better enforce the integrity of the database. You are assigning PAID_ID in code of a form...what if data gets added to the table via another method (not using the form)?
Just some of my thoughts.
Steve Gibson