How to pull field from related table

P

Paul B.

Hello all....

I need to pull the field [ServiceCentreName] from the tblServiceCentreInfo.
On my form, I have a reference to the field [ServiceCentreNumber] in the
tblVehicleInfo.

I want to display the [ServiceCenterName] on the form instead of the
[ServiceCenterNumber]

I am current using:
DLast("[ServiceCenterNumber]","tblVehicleInfo","[VehicleNumber]="_
&[VehicleNumber])

to get the ServiceCenterNumber onto the form.

Thanks in advance
 
M

Marshall Barton

Paul said:
I need to pull the field [ServiceCentreName] from the tblServiceCentreInfo.
On my form, I have a reference to the field [ServiceCentreNumber] in the
tblVehicleInfo.

I want to display the [ServiceCenterName] on the form instead of the
[ServiceCenterNumber]

I am current using:
DLast("[ServiceCenterNumber]","tblVehicleInfo","[VehicleNumber]="_
&[VehicleNumber])


A DLookup would be a little clearer than DLast.

It looks like you're trying to get the name from the wrong
table. Try something more like:

DLookup("ServiceCentreName", "tblServiceCentreInfo",
"ServiceCentreNumber=" & Me.ServiceCentreNumber)

If you're using that as a text box expression, don't forget
the = sign in front.

Alternatively, it would probably be faster and easier if you
joined the two tables in the form's record source query:

SELECT tblVehicleInfo.*,
tblServiceCentreInfo.ServiceCentreName
FROM tblVehicleInfo INNER JOIN tblServiceCentreInfo
ON tblVehicleInfo.ServiceCentreNumber =
tblServiceCentreInfo.ServiceCentreNumber
 
P

Paul B.

Thanks Marshall



Marshall Barton said:
Paul said:
I need to pull the field [ServiceCentreName] from the tblServiceCentreInfo.
On my form, I have a reference to the field [ServiceCentreNumber] in the
tblVehicleInfo.

I want to display the [ServiceCenterName] on the form instead of the
[ServiceCenterNumber]

I am current using:
DLast("[ServiceCenterNumber]","tblVehicleInfo","[VehicleNumber]="_
&[VehicleNumber])


A DLookup would be a little clearer than DLast.

It looks like you're trying to get the name from the wrong
table. Try something more like:

DLookup("ServiceCentreName", "tblServiceCentreInfo",
"ServiceCentreNumber=" & Me.ServiceCentreNumber)

If you're using that as a text box expression, don't forget
the = sign in front.

Alternatively, it would probably be faster and easier if you
joined the two tables in the form's record source query:

SELECT tblVehicleInfo.*,
tblServiceCentreInfo.ServiceCentreName
FROM tblVehicleInfo INNER JOIN tblServiceCentreInfo
ON tblVehicleInfo.ServiceCentreNumber =
tblServiceCentreInfo.ServiceCentreNumber
 

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