MS-Access using Dlookup to pull results from query into textbox on form

2.4k Views Asked by At

I am very new to access and I am using the Dlookup function to pull the results from a query into a text box to appear on a form. I have the following expression in the Data Control Source field for the text box and it is pulling in the very first result from the query. =DLookUp("SumOfSales","qTtlSalesbyComp","Company = Company")

I need it to act as a vlookup and match the Company in the query to the Company in the Company text box and pull the SumofSales that corresponds. Any hep would be greatly appreciated.

2

There are 2 best solutions below

2
SunKnight0 On

If Company is text:

=DLookUp("SumOfSales","qTtlSalesbyComp","Company = '" & Company & "'")

If it is numerical:

=DLookUp("SumOfSales","qTtlSalesbyComp","Company = " & Company )
0
chef On

I just could not seem to get the Dlookup to work. I ended up using subforms to pull in the query results. I believe this ended up being a much cleaner way of executing what I wanted.