HELP : Fill Fields automatically on form based on a control's value

  • Thread starter Stéphane Vallières
  • Start date
S

Stéphane Vallières

HI Can someone help me

I'm using access 2003 I want to create an invoice and I want some field to
be create automatically.

I want the field lastname and name of the employe to fill out auto when I
enter the employe number

I' ve tried this code

Sub No Employé_onExit (Cancel As Integer)

Dim varNomEmp as Variant

varNomEmp = DLookup("Nom Employé", "employés", "Nom employé =
[Nom employé] ")

if (Not IsNull(varNomEmp))= true Then [Nom employé] = varNomEmp

End Sub



but it's not working...I have no clue of what I'm doing wrong



Thanks in advance

Stéphane

(e-mail address removed) to reply
 
S

Squirrel

Hi Stephane,

This is my setup:

tblEmployees
fields: EmployeeID
LastName
FirstName

tblInvoices
fields: InvoiceID
EmployeeID

tblInvoiceDetails
fields: InvoiceID
any other fields here

Main form + subform for InvoiceDetails
Main form recordsource is a query:
"SELECT tblInvoices.InvoiceID, tblInvoices.EmployeeID,
tblEmployees.LastName, tblEmployees.FirstName FROM tblEmployees INNER JOIN
tblInvoices ON tblEmployees.EmployeeID = tblInvoices.EmployeeID;"

So the main form has fields InvoiceID, EmployeeID, LastName and FirstName.
The EmployeeID field is designed as a combobox with recordsource "Select
EmployeeID from tblEmployees".
As soon as the EmployeeID is selected in the combobox the LastName and
FirstName controls are automatically populated via the above query. For the
LastName and FirstName set the property Locked = Yes so that the name
textboxes behave as display only rather than updatable.

Hope this helps. -Linda
 

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

Top