Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Appending Records To A Table with append and scatter mem
Message
From
12/04/2002 02:23:35
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00644109
Message ID:
00644113
Views:
14
>I would like to know how I can append records to a table from a form using the FoxPro Append command.
>
>I have a form with with a single table in the data environment and three fields on the form. One of the fields is the primary index. The control source of each text box is linked to the appropriate table field. I have a Add and Save button on the screen. The following code is attached to the Add Button:
>
>THISFORM.txtApp_code.VALUE = ""
>THISFORM.txtApp_name.VALUE = ""
>THISFORM.txtApp_owner.VALUE = ""
>
>SELECT SecMod
>
>
>SCATTER MEMVAR MEMO
>
>The following code is attached to the Save button:
>app_code = THISFORM.txtApp_code.VALUE *app_code is name of table field
>app_name = THISFORM.txtApp_name.VALUE
>app_owner = THISFORM.txtApp_owner.VALUE
>
>APPEND BLANK
>GATHER MEMVAR
>
>When I have entered data into the text boxes and I click on the Save button, the program boms out with the error "Uniqueness of index App_code violated".

So the app_code is the same as in another record, and if it's set as a primary or candidate key, then you get this message. Unique keys mean exactly that - VFP will not allow you to have two records with the same value of that key. If this happens when you Append Blank, that means you already have one record with a blank key; uniqueness of this key makes that impossible, and you'll have to tablerevert().

>A blank record is created and the contents of the first record of the table is overwritten with that which I just entered. It would appear to me that the record pointer is in the wrong position. How do I get the record pointer to point to the blank record and save the data there? If I remove the control source links in the text boxes, I do not get this error. But with this done, the text boxes are not populated with any data when the form is loaded.

The blank record is created but can't be saved. If you're using the unbound controls, you have to write your own code to refresh them and to save their values. Scatter/gather is not the best way to do it, but at least it gives you a chance to do it in one line. Instead of append/gather, simply
insert into (alias here) from memvar
That way you don't have that one step when you have a blank record.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform