If I want to lookup fields in a table such as EmployeeNumber, FirstName, LastName, DeptNo and assign to 4 different variables, I have to use the DLookup function 4 times. Is there an easier or more efficient way to do this?
SELECT EmployeeNumber, FirstName, LastName, DeptNo
FROM a table
WHERE criteria = somevalue
open that in a recordset, now you can do what you want with it:
Code:
dim db as dao.database
dim rs as dao.recordset
set db = currentdb
set rs = db.openrecordset("queryname or SQL string")
Do while not rs.EOF
debug.print rs![Employeenumber] & " " & rs![Firstname] etc
rs.movenext
Loop
It was only hard because you didn't know how to do it.
I'd try and convince you to not use SELECT * in your production code/queries. It works for sure, but if you know you want "EmployeeName" from your table, SELECT it specifically. Other than reducing the amount of data that you retrieve from the database it makes it very clear what the query or SQL string is supposed to be doing when you come back to it in 6 months time and try and figure out what it was up to.