Search This Blog

Showing posts with label save. Show all posts
Showing posts with label save. Show all posts

Edit Save Code


Most of the time neophyte VFP Programmers know how to add, edit and save data on the table. But how can we improve the form design? This is a sample I usually used, to ask or confirm if the User want to edit dat. A confirmation message box will appear with a 'Yes' or 'No'. From that the User can choose which will be the next function.

lAnswer = MESSAGEBOX("Save and update Counter Dispatch?", 4, "Confirmation")
IF lAnswer = 6
SELECT sviewbranch
LOCATE FOR IdNum = THISFORM.Text12.Value
IF FOUND()
REPLACE beginbal WITH THISFORM.TEXT1.Value
REPLACE branchname WITH THISFORM.TEXT2.Value
REPLACE branchaddress WITH THISFORM.TEXT3.Value
REPLACE branchdesc WITH THISFORM.TEXT4.Value
REPLACE debit WITH THISFORM.TEXT5.Value
REPLACE credit WITH THISFORM.TEXT6.Value
REPLACE netchange WITH THISFORM.TEXT7.Value
REPLACE ending WITH THISFORM.TEXT8.Value
REPLACE branchdescnum WITH THISFORM.TEXT9.Value
THISFORM.REFRESH
ENDIF

Add, Save , Replace Code

Sample of save, add, append and replace code:

Select PERSONALINFO
Replace NAME With Thisform.Text1.Value
Replace AGE With Thisform.Text2.Value
Replace BIRTHDATE With Thisform.Text3.Value
Replace BIRTHPLACE With Thisform.Text7.Value
Replace ADDRESS With Thisform.Text8.Value
Replace LANDLINE With Thisform.Text9.Value
Replace CELLPHONE With Thisform.Text10.Value
Replace EMAIL With Thisform.Text11.Value
Replace WEBSITE With Thisform.Text12.Value

SELECT TableName
APPEND BLANK
REPLACE FieldOne WITH THISFORM.TEXT1.VALUE
REPLACE FieldTwo WITH THISFORM.TEXT2.VALUE
REPLACE FieldThree WITH THISFORM.COMBO1.VALUE
REPLACE FieldFour WITH THISFORM.COMBO2.VALUE
INSERT INTO TableName (FieldOne, FieldTwo, FieldThree,FieldFour);
VALUES (THISFORM.TEXT1.VALUE, ;
THISFORM.TEXT2.VALUE, ;
THISFORM.TEXT3.VALUE, ;
THISFORM.TEXT4.VALUE)

Second saving a data by Edit:

SELECT TableName
REPLACE FieldOne WITH THISFORM.TEXT1.VALUE
REPLACE FieldTwo WITH THISFORM.TEXT2.VALUE
REPLACE FieldThree WITH THISFORM.COMBO1.VALUE
REPLACE FieldFour WITH THISFORM.COMBO2.VALUE
INSERT INTO TableName (FieldOne, FieldTwo, FieldThree,FieldFour);
VALUES (THISFORM.TEXT1.VALUE, ;
THISFORM.TEXT2.VALUE, ;
THISFORM.TEXT3.VALUE, ;
THISFORM.TEXT4.VALUE)