PDA

View Full Version : Having a problem prepopulating fields



lucpian
04-30-2008, 12:05 PM
Hi All,


I am having a problem. I am working with an access form that everything works okay, except that I would like if the client enters the Employee_ID, and hits the enter key, it should automatically prepopulate the other associated fields without requiring one to scroll through the over 9000 records. Please, I need your help.

Thanks

Lucpian

CreganTur
04-30-2008, 12:35 PM
Are you wanting to populate these other fields with field values assocaited with the Employee_ID?

i.e.: EmployeeFirstName, EmployeeLastName, etc.

Do these values exist in a table where they are already associated with Employee_ID?

Can you give an example of what fields you want to be filled in that are assocaited with Employee_ID?

lucpian
04-30-2008, 12:59 PM
Yes, a table exist where these fields are associated with each Employee_ID. Some of the fields are EMP_Fname, EMP_Lname, EMP_Mname, Trans_Date, Trans_Amount, Exp_Date and UBalance.

Thanks

Lucpian

CreganTur
05-01-2008, 05:11 AM
Try this: put this code behind a button-click event. You'll need to change a couple of things on your form also before you use it (I'd put it behind its own button for testing purposes)

In the code below change [TextBox] to the name of the text box where Employee_ID is entered. Also, for every text box you want populated, you'll need to change the Name and Control source to the field name. Example: the text box where you want the employee's first name you need to change the Name and Control Source to EMP_Fname.

Put an employee ID in and click your new test button- it should populate all the fields listed in the SQL SELECT statement automatically.

sql1 = "SELECT qryName.EMP_Fname, qryName.EMP_Lname, _
qryName.EMP_Mname, qryName.Trans_Date, qryName.Exp_Date, _
qryName.UBalance
FROM qryName
WHERE qryName.Employee_ID= '" & Me![TextBox] & "'; "
Me.RecordSource = sql1
Me.Requery