Defaulting a value in form

flmngldn

New member
Local time
Yesterday, 18:45
Joined
Feb 26, 2005
Messages
5
I am having problem putting a default value in a field based on the entry of the previous field.
We have an Employee table that contains Employee info plus its Department key. Then we have a Department table that contains the Department code and description. I would like to default the department code when an employee is entered.
I am having problems attaching the database. If you need to see the database please let me know and I can email it to you.
Unfortunately I did not create this database and I am new to Access and have to support it.
The form is "Labor Transaction" and want to default a value in 'Department' feild based on the Employee. This field should show the default value but can be changed to another department from the pull down list. Please help
:eek:
 
if u want to make only one department as a default value for all new employee entered than there is a property of field called "Default value", so write down the name of the dept in that property.

OR if u want to give value of the dept accroding to the emp_code than in the "LostFocus" event of emp_code, check the emp_code value and write dept.value = "value u wnat".
 
The way the database is setup is there are say 20 employees which belong to one of the 5 dept in the Department list. So when a user goes in to enter timesheet info they will choose the Employee from the list and we would like to default the dept field in the form to the dept. that is defined in the employee table. How wouldI do this?
eg
James Block Eng
Jane Cole MFG
Justine Jones Admin

In the timecard form if they pick 'Jane Cole' I would like the dept field default to 'MFG' but keep this a combo box so the user can change the dept to 'Admin' if they have spent some time doing 'Admin' work.
 
so u want the dept of the employee to display in the dept combo box

then on the employee's combobox's LostFocus event write code to select the dept of the selected employee and then display it in the dept combo.

code:
Private Sub emp_code_LostFocus

dim c, r as object
dim s as string

set c =application.currentproject.connection
set r = createobject("ADODB.Recordset")

s = "Select dept from [ur table name] where emp_code = '" & me![emp_code] &"'"

r.open s, c, 1
if r.recordcount <> 0 then
me![dept field name] = r![dept]
endif

r.close
set c = nothing

end sub

I write the field names in this code by myseflf. U write the field name according to ur form.
 

Users who are viewing this thread

Back
Top Bottom