Search This Blog

Report Code

Calling a report from a form is very easy. You can even call a multiple reports that comes from your application. Microsoft Visual FoxPro is very flexible, you do not have to install other application in making print reports. VFP 's built in reports can call view from a table either local or through local area connection such as SQL from a server.

txtName = ALLTRIM(THISFORM.txtName.VALUE)
txtBirthDate = ALLTRIM(THISFORM.txtBirthDate.VALUE)
txtBirthPlace = ALLTRIM(THISFORM.txtBirthPlace.VALUE)
REPORT FORM "C:\ProjectName\Reports\Resume" TO PRINTER PROMPT NODIALOG PREVIEW

Edit Save Code

Microsoft Visual FoxPro programming language has a lot of code to edit, insert, replace or save. Using select, append, insert or replace is some of the ways to save data. I always use the select and replace because it is easy to troubleshoot when your code has a problem.

SELECT InfoNumber
LOCATE FOR IdNum = THISFORM.txtIdNum.VALUE
IF FOUND()
SELECT InfoNumber
REPLACE LastName WITH ALLTRIM(THISFORM.txtLastName.VALUE)
REPLACE FirstName WITH ALLTRIM(THISFORM.txtFirstName.VALUE)
REPLACE MiddleName WITH ALLTRIM(THISFORM.txtMiddleName.VALUE)

Do Case Code

When you have a multiple case which you would want a different action, you can use the Do Case. Do case is very useful code when used wisely.

DO CASE
CASE THISFORM.txtSqlId.VALUE = 1
MESSAGEBOX("Argentina", "Information")
CASE THISFORM.txtSqlId.VALUE = 2
MESSAGEBOX("Bangladesh", "Information")
CASE THISFORM.txtSqlId.VALUE = 3
MESSAGEBOX("Malaysia", "Information")
CASE THISFORM.txtSqlId.VALUE = 4
MESSAGEBOX("Philippines", "Information")
CASE THISFORM.txtSqlId.VALUE = 5
MESSAGEBOX("Taiwan", "Information")
CASE THISFORM.txtSqlId.VALUE = 6
ENDCASE

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.