Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a combo in a grid to autofill other grid values

Status
Not open for further replies.

hallm

Programmer
Jun 11, 2000
159
US
I've got a form that just consist of some header information at the top and then a grid control that contains employee names and ssn numbers. I've made the employee name column a combo box. I'm wanting to be able to select the employee name in the combo and have it automatically fill the ssn column and maybe other fields. What is the best way to acomplish this?

Thanks,

Marion
 
You could add code to the Click event of the combo box which would do a lookup on the name, then have it do a SCATTER of the table and a populate the grid using memvars as the control source, or a GATHER FIELDS.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Hi Marion.

I've got a form that just consist of some header information at the top and then a grid control that contains employee names and ssn numbers. I've made the employee name column a combo box. I'm wanting to be able to select the employee name in the combo and have it automatically fill the ssn column and maybe other fields.

Why? What is the purpose of the data you are displaying in the grid? There may be a better way to do what you are trying to do ;-)



Marcia G. Akins
 
Its a form where the grid just has employee information like Emp Name, ssn, etc.

I would be happy if I had a button on the form that would autofill the grid with active employee's and their ssn's, the other stuff has to be manually keyed each time.

Marion
 
Hi Marion.

I would be happy if I had a button on the form that would autofill the grid with active employee's and their ssn's, the other stuff has to be manually keyed each time.

It is eaven easier than this ;-). What you need to do is to create a local view on the Employee table that contains only active employees. You can drop the view right into the form's DE and use that as your grid's RecorSource.

No button required.




Marcia G. Akins
 
Would that effect prior dates if you made an employee inactive? The grid's source is another table that has the detail information like monthly salary and employee contributions. What I'm needing is to populate a new record with the active records, but still give them the ability to delete individual child records from the grid and have it retain that information later on.
 
I've been looking up the SCATTER and GATHER commands and this seems like something that would work. The onclick on a button would start with the following code.

dValue = THISFORM.paydatevar.Value && This gets the key date from the form
SELECT employeedetails.employeename, employeedetails.ssn;
FROM mers!employeedetails;
WHERE employeedetails.active = TRUE;
ORDER BY employeedetails.employeename;
INTO CURSOR temp

SELECT temp

SCAN
&& This is where I'm sort of lost. How do select my employeepay table which is the one that will finally store the information and have SCATTER GATHER fill the table with employeenames and ssn's from the above cursor. I was thinking something like:

USE employeedetails
SCATTER MEMVAR BLANK
m.employeename = temp.employeename
m.ssn = temp.ssn
APPEND BLANK
GATHER MEMVAR

END SCAN

I'm playing with that code right now trying to get it to work. If there is a better way please let me know.

Thanks,


Marion
 
Hi Marion.

I've been looking up the SCATTER and GATHER commands and this seems like something that would work.

SCATTER and GATHER go back to FoxBase+ and there are much better wasy to do what you are trying to do these days ;-) VFP version 9 has greatly enhanced the SQL syntax. Lookin at your code, I am still not sure what you are trying to do. It looks to me like you are trying to insert a bunch of records into the employeeDetails table for active employees that already exist in this table.

To add a bunch of records to employeeDetails for the active employees, try this ( I am assuming that Active is a logical field (if it isn't, just change the syntax appropriately for the data type):

Code:
INSERT INTO EmployeeDetails ( EmployeeName, SSN ) SELECT EmployeeName, SSN FROM EmployeeDetails WHERE Active

You do not need the order by clause. All you need is an index tag on the EmployeeDetails table on UPPER( EmployeeName )




Marcia G. Akins
 
I made a mistake in my prior code, it's actually

USE payrolldetails
SCATTER MEMVAR BLANK
m.employeename = temp.employeename
m.ssn = temp.ssn
APPEND BLANK
GATHER MEMVAR

But it looks like your sql statement will work alot easier. I'll give that a try.
 
The SQL statement works fine. Whats the best way to refresh the grid so that the records show up as soon as the button is clicked?

Thanks,

Marion Hall
 
Hi Marion.

Whats the best way to refresh the grid so that the records show up as soon as the button is clicked?

I assume that the grid is set up with its RecordSource set to PayrollDetails. After you insert the records into the table, refresh the grid.

Code:
Myform.grdPayrollDetails.Refresh()





Marcia G. Akins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top