Search This Blog

Export Code

Use this code when you want to export data from table to Excel File. Plus with a message box informing you if you want to do so. There is also a message box that telling you that you have successfully exported your table to an Excel File.

lAnswer = MESSAGEBOX("Generate Report, do you wish to continue?", 4, "Generator")
IF lAnswer = 6
SELECT SeafarerList
=REQUERY("SeafarerList")
COPY TO "C:\SEAFARER.XLS" XL5
=MESSAGEBOX("File successfully generated.", "Successful")
ENDIF

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

Retrieve Code


If you want to have an easy way to retrieve data and have it appear in a text box or combo box just by clicking a single data from that row, there is a simple remedy for that. Just follow the following code and paste it on click.

THISFORM.Text1.VALUE = sviewbranch.beginbal
THISFORM.Text2.VALUE = sviewbranch.branchname
THISFORM.Text3.VALUE = sviewbranch.branchaddress
THISFORM.Text4.VALUE = sviewbranch.branchdesc
THISFORM.Text5.VALUE = sviewbranch.debit
THISFORM.Text6.VALUE = sviewbranch.credit
THISFORM.Text7.VALUE = sviewbranch.netchange
THISFORM.Text8.VALUE = sviewbranch.ending
THISFORM.Text9.VALUE = sviewbranch.branchdescnum

Read Only Code

Thisform.Text1.ReadOnly = .T.
Thisform.Command1.ReadOnly = .T.
Thisform.Grid1.ReadOnly = .T.
Thisform.Pageframe1.ReadOnly = .T.
Thisform.Combo1.ReadOnly = .T.