2 Related field or Auto fill up 2nd field after 1st field entered

K

Kaoli

I have 2 related field in a transaction table
Example "Taxi Number" (1st Field) "Taxi Driver" (2nd Field)
Let say i have a table having latest or default Driver driving which taxi
record as per below

TaxiNumber TaxiDriver
New York 1111 Micheal
New York 2222 Jodan
.....

Now if i entred New York 1111 into "Taxi Number" (1st Field) in the
transaction table can "Taxi Driver" (2nd Field) auto filling with Micheal
into the field? but i still able to change "Taxi Driver" (2nd Field) as Jadan
or other driver because maybe today he taking leave and replace by other
driver.

TaxiNumber TaxiDriver
New York 1111 (after entered) Micheal (auto filled but still able
to change to other
driver)
 
D

Douglas J. Steele

How are you entering the taxi number?

If you're using a combo box (which would be the preferred approach), make
sure that the combo box also contains the driver name, even if it isn't
displayed. In the AfterUpdate event of the combo box, put code like:

Private Sub cboTaxiNumber_AfterUpdate()
Me.txtTaxiDriver = Me.cboTaxiNumber.Column(1)
End Sub

This assumes that the driver name is the 2nd column in the combo box (the
Column collection starts numbering at 0)

If you're using a text box, you'll need to do a look-up in the AfterUpdate
event. You should be able to use something like:

Private Sub txtTaxiNumber_AfterUpdate
Me.txtTaxiDrive = DLookup("[TaxiDriver]", "[Drivers]", "[TaxiNumber] = '"
& Me.txtTaxiNumber & "'")
End Sub

cboTaxiNumber is supposed to be the name of the combo box being used if
that's the route you're going while txtTaxiNumber would be the name of the
text box you key the taxi number into if using that route. txtTaxiDriver is
the text box to hold the driver name. I've assumed that the data is stored
in a table named Drivers, and that the relevant fields in that table are
TaxiNumber and TaxiDriver. Replace those names with whatever your actual
names are.
 

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