Access Form Dlookup - Using a Combo box for the expression value

Michael Noze
Michael Noze used Ask the Experts™
Hi Experts,

I'm trying to populate a text box with a Dlookup based on a combobox value.
Form containing the combobox: frmInspection
combobox: cboEquipment
table: tblEquipment
Unique ID in the table: [EquipementID]
Field wanted in the textbox: [HS]

This is the code I've tried but didn't work:

Set rst2 = CurrentDb.OpenRecordset("tblEquipment")
With rst
            Forms("frmInspection").Form.Controls("txtHS") = _
            DLookup(.Fields("HS"), "tblEquipment", Forms("frmInspection").Form.cboEquipement = _
End With

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012
Me.<name of control or field> = DLookup("HS", "tblEquipment", "[EquipmentID] = " &  Me.cboEquipement)

  This would assume that the ID is numeric and that this is running in the form.



Thanks! It worked perfectly!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial