Search code examples
vbams-accessms-access-2003

DLookup ControlSource


Summary: I want to display a value (in a text box) stored in another form upon choosing specific values from combo boxes. I want to pass the two combo box values I have into the DLoopup property but every time I do so it gives me an error.

Below is the code is inserted in the control source property of a text box:

=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] ='" & [Combo5] & "'")

This gives me an "#Error" in the text box.

Also tried the following but gives me "#NAME" error:

=DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] = '" & [Combo5.Value] & " And [Program_Name] = '" & [Combo7.Value] & "'")

Solution

  • You need to get your delimiters sorted out. AFAIR Budget Year is a number:

     =DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] =" & [Combo5])
    

    When you are passing a value to a numeric type field, you do not use delimiters, for text, you use quotes, either 'Abc' or "Abc", for dates, use hash (#) #2012/11/31#.

     =DLookUp("[Year_ended]","1_Supportive_Housing","[BudgetYear] =" & [Combo5]  & " And [Program_Name] = '" & [Combo7.Value] & "'")