Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Two Parent Problem
Message
From
14/07/2001 04:47:15
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
13/07/2001 21:51:25
Michael Gass
Instructional Software, Inc.
Kirkland, Washington, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00530093
Message ID:
00530618
Views:
17
>I do need to restrict the list of employees to only those who work for the selected company. You said:
>
>>* Assuming we don't want to restrict to employee of selected company
>>* Otherwise add a where clause like
>>* where employee.compid = crsComps.CompId
>
>The employee table doesn't have a compid field. The compid field is located in the 'joining' table between the company table and the employee table. (The joining table is the table with the job titles for each employee in each company which is what I want to display.) In the joining table I have a compid and emplid for every company and every employee. If I put the compid field in the employee table it would expand the table by a multiple of the number of companies. So, now I'm faced with the problem of how to list only the employees of the selected company in the employee list when ever a company is changed in the company list. Any ideas???

Michael,
It wouldn't matter much. You can have complex join queries for listbox. I assume you have something like :

Company, compid - companies (crsComp for listbox)
EmpName, empid - employee (crsEmp for listbox)
empid, compid, anyotherfields - this is a separate one or jobs itself (let's say Linker)
*Employee listbox
.Rowsource = "select first-(', '+last) as empname, empid "+;
  "from employee "+;
  "where empid in "+;
  "(select emp_id from Linker where compid=crsComp.compId) "+;
  "into cursor crsEmp"
All you need is to find correct SQLs first :) Above SQL might be one with joins too. BTW not needed here but you're even free to use form objects in your expressions. ie :
.Rowsource = "select first-(', '+last) as empname, empid "+;
  "from employee "+;
  "where empid = thisform.txtEmpId.Value and "+;
  ...
With restriction on employee probably you'd need this code in company listbox.valid (or interactivechange but I prefer valid for performance reasons) :
*complist.valid
with this.parent.lstEmp
 luEmpId = crsEmp.EmpID && Save current empid
 .Requery && Requery listbox hence new crsEmp cursor
 select crsEmp
 locate for empId = luEmpId && Does previous selected exists in this set ?
 .ListIndex = iif(eof(),0,recno()) && If not clear selection else select again
endwith
*Also adjust Jobs listbox...
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform