Article ID: 156169
Article Last Modified on 6/30/2004
Visual FoxPro 3.0: Samples\Mainsamp Visual FoxPro 5.0: Samples\Tastrade Visual FoxPro 6.0: _samples variable
IF "6.00" $ VERSION()
cdir = _samples + "Tastrade"
ELSE
IF "5.00" $ VERSION()
cDir = HOME()+"SAMPLES\TASTRADE"
ELSE
cDir = HOME()+"SAMPLES\MAINSAMP"
ENDIF
ENDIF
OPEN DATABASE cDir+"\DATA\TASTRADE.DBC" EXCLUSIVE
CREATE SQL VIEW MyView as SELECT *;
FROM tastrade!Employee;
WHERE ((ALLTRIM(Employee.employee_id)==?vEmpid);
OR (EMPTY(?vEmpid)=.T.));
AND ((Employee.title == ?vTitle;
OR (EMPTY(?vTitle)=.T.)))
Save it as MyViewCode.prg and then Run the program.
Text Box
Name: Text1
Text Box
Name: Text2
Grid
Name: Grid1
RecordSource: MyView
Command Button
Name: Command1
Caption: Requery
Command Button
Name: Command2
Caption: Clear
vEmpid=Thisform.Text1.Value
vTitle=Thisform.Text2.Value
=REQUERY('MyView')
ThisForm.Refresh
Thisform.Text1.Value=""
Thisform.Text2.Value=""
Thisform.Refresh
Text1 Text2 Results
--------------------------------------------------------
<blank> <blank> All records are return
1 <blank> One record with Employee ID is 1
1 Sales Manager One record with Employee Id is 1
and Title is Sales Manager
<blank> Sales Manager Two records return with Title being Sales Manager
2 Sales Manager No records are returned
CLOSE DATABASE
IF "6.00" $ VERSION()
cdir = _samples
ELSE
IF "5.00" $ VERSION()
cDir = HOME()+"SAMPLES\TASTRADE"
ELSE
cDir = HOME()+"SAMPLES\MAINSAMP"
ENDIF
USE cDir+"\DATA\employee.dbf"
CLEAR
ACCEPT "Enter an Employee ID: " to vEmpid
ACCEPT "Enter an Employee Last Name: " to vTitle
SELECT *;
FROM tastrade!Employee;
WHERE ((ALLTRIM(Employee.employee_id)==?vEmpid);
OR (EMPTY(?vEmpid)=.T.));
AND ((Employee.title == ?vTitle;
OR (EMPTY(?vTitle)=.T.)))
Keywords: kbhowto kbsqlprog KB156169