Dlookup an entire column

G

Guest

Is there a way to perform a DLookup in a query that will find the entered
header name? I want the entire column to be returned and not just the first
cell of the desired column. I tried DLookup("ColumnDesired","TableName") and
the first cell value of that column repeats itself for all rows. What type
of criteria could I enter to return the correct data in each row?

Thanks,
Matt
 
G

Graham R Seach

Matt,

No, DLookup only ever returns a single value.

To return an entire column in code, you must use a recordset:
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT Column1 FROM Table1")

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
M

MacDermott

Add the table where the headers are stored to your query, and link the
relevant fields.
Now you can simply add your "ColumnDesired" field to the query grid.

HTH
- Turtle
 

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