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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofill, afterupdate question 3

Status
Not open for further replies.

gscma1

Technical User
Jun 27, 2006
94
GB
I have a form 'frmHours' whereby the user enters data about an employees hours worked and cash required each week.

cboEmpId
cboWeekNo
cboPeriod
Hours
Cash

is it possible to have a text field update with the employee name, when the empid combo box has been selected?

also 'tblemployees' contains details of empid, forname, surname, wage rate, cash required weekly, etc...

is it possible for my 'frmHours' to autofill the cash field with the amount of cash they require weekly from 'tblEmployees'???

Many Thanks
 
Put the code you are using in the On Current event of the form.
 
At the moment you have code in an after update event for EmpID yesno? You need to look at the events for the form, on of which is On Current and repeat the code there.

However, now that you have the code sorted out, it should be simple enough to transfer the dlookup line to a textbox, which would get rid of all this fiddling around with code. If you post the code you are using, someone will show you how to alter it to fit a textbox.
 
Far easier that the dlookup methed...

Create a comboBox based on the cboEmpId, cboWeekNo, cboPeriod, Hours and Cash fields (i'd personally base the comboBox rowsource on a query)

create unbound text boxes on your form for each of these fields.
put in their control source...

=TheNameofYourComboBox.column(1)

change the column number in the above for the appropriate fieldormation you want to display in the textbox .

in the afterupdate event of the combobox put ...

Private Sub TheNameofYourComboBox_AfterUpdate()
Me.Recalc
End Sub

This will give you what your after.


Ian Mayor (UK)
Program Error
Programming is 1% coding, 50% error checking and 49% sweat as your application bombs out in front of the client.
 
Remou, when you say repeat the code in the oncurrent event, which i have now found, what exactly do you mean i have put this but i am aware that this is worng:

Private Sub Form_Current()
EmpId_AfterUpdate()
Me.txtForename = DLookup("[Forename]", "tblEmployees", "[EmpId]=" & Me.EmpId.Column(0))
Me.txtSurname = DLookup("[Surname]", "tblEmployees", "[EmpId]=" & Me.EmpId.Column(0))
Me.txtCash = DLookup("[Cash]", "tblEmployees", "[EmpId]=" & Me.EmpId.Column(0))
End Sub
 
Try:
Code:
Private Sub Form_Current()
Me.txtForename = DLookup("[Forename]", "tblEmployees", "[EmpId]=" & Me.EmpId.Column(0))
Me.txtSurname = DLookup("[Surname]", "tblEmployees", "[EmpId]=" & Me.EmpId.Column(0))
Me.txtCash = DLookup("[Cash]", "tblEmployees", "[EmpId]=" & Me.EmpId.Column(0))
End Sub

You can create an unbound textbox, and set the Control source to:
[tt]= DLookup("[Forename]", "tblEmployees", "[EmpId]=" & EmpId.Column(0))[/tt]
Which will cut down on the code.

And please look at the other suggestions, especially ProgramError's.
 
Indeed ProgramError's suggestion is more straight forward, I also suggest going with it.

"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top