DLookup code for auto-populating a control on a form

P

pedro

I am trying to auto-fill a combo-box on a form based on the selection from
another combo-box.

It is triggered on an after update event on the first combo-box selection.
The code I have is;

If not IsNull([Vehicle Model]) Then
Dim org as Variant
Dim pName As String
pName = [Vehicle Model].value

org = DLookup("shape","tbl_vehmodel","model = ' " & pName & "'")

End If

Shape is a field in the table tbl_vehmodel that I want to lookup based on
the name of the vehicle model selected in the combo-box. The combo-box I want
to auto-fill is called Vehicle Shape.

The syntax runs without errors however the Vehicle Shape field is not
populated.

Your suggestions would be greatly appreciated.
 
D

Dennis

Don't know if it is just a typing error but you have a space after the first
apostrophe.
The line should be
org = DLookup("shape","tbl_vehmodel","model = '" & pName & "'")

Also DLookup will only return 1 value, so why are using a combo box to
display 1 value ?
 

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