default value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to set a default value in a form "Event" - linked to a table
"Event". The form has several fields, the two that i'm working with are
Employee and PayRate. I'd like for the default value of PayRate to show up
as whatever was entered last for the Employee. I'm guessing I should use the
DLast function, but can't seem to get the expression right. Any thoughts?

Thanks!
 
From your post I can't tell how you know which record is the last one.
Try to fit this dlookup combined with dmax

On the load event of the form, enter the code:
Me.PayRateFieldName.DefaultValue = Dlookup("PayRate","TableName","Employee
=" & Me.Employee & " And KeyField =" & Dmax("KeyField","TableName","Emloyee="
& Me.Employee))

Note
1. Me.Employee = the name of the employee field in the form
2. KeyField = The field that I can use to bring the last record (counter,
date)
3. All the filers above you can use if the field are number type
For string add single quote before and after
Me.PayRateFieldName.DefaultValue = Dlookup("PayRate","TableName","Employee
='" & Me.Employee & "' And KeyField ='" &
Dmax("KeyField","TableName","Emloyee='" & Me.Employee & "'"))

For Date add # before and after
Me.PayRateFieldName.DefaultValue = Dlookup("PayRate","TableName","Employee
='" & Me.Employee & "' And KeyField =#" &
Dmax("KeyField","TableName","Emloyee='" & Me.Employee & "#"))

4. Good luck
 
One more thing
If the employee number is not entered when the form is open, then put that
code on the after update event of the employee field.
 
Pardon me for jumping in, Ofer, but I don't think this will work. The
default value is only applicable at the point where a new record is
started. If there is already data anywhere, or you are relying on the
entry of data, then it is too late to use the default value of anything.
 
Thank you Steve, for jumping in.
You are so right, in that case on the after update event of the employee
field, remove the default part

Me.PayRateFieldName = Dlookup("PayRate","TableName","Employee
=" & Me.Employee & " And KeyField =" & Dmax("KeyField","TableName","Emloyee="
& Me.Employee))

Thanks, Steve.
 
Thanks so much guys! I'll try this. The Employee is a name, and the table
records are autonumbered, that's how I'd know what was the last entry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top