Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Any M$ Access Programmers? Familiar with DLookup?

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » The DU Lounge Donate to DU
 
Hawkeye-X Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jul-14-04 01:59 PM
Original message
Any M$ Access Programmers? Familiar with DLookup?
I'm trying to figure out how exactly the function would work for us...

Hawkeye-X
Printer Friendly | Permalink |  | Top
orthogonal Donating Member (424 posts) Send PM | Profile | Ignore Wed Jul-14-04 02:26 PM
Response to Original message
1. Google is my friend; I apparently am yours
Edited on Wed Jul-14-04 02:34 PM by orthogonal
I've never heard of this (I'm not a Access programmer), but a quick googling explains that DLookup is apparently shorthand for a query.

It takes three arguments, a column ("field") name, a table name, and a where clause.

If the sql select were
select foo from bar where baz = 1

the corresponding DLookup would be
DLookup( "foo", "bar", "baz = 1" )


The field name may be a computed field, e.g., for this sql:
select firstname + ' ' + lastname from bar where baz = 1

the corresponding Dlookup would be
DLookup( "firstname + ' ' + lastname", "bar", "baz = 1" )

The main use seems to be as a correlated subquery in forms.

In sql, if we have an employee table with employee data including a department number to which the employee belongs, and a department table with department names, we might use a correlated subquery to select employee and department names (it would of course be simpler, and would run faster, just to use a join in this, but not in all, cases).

It's call a "correlated" subquery because the subquery's where clause is dependent on the main query's result. So for each row in the main query, a separate subquery is done (and that's why it's often slower). The sql would be:
select a.empname,
(select b.deptname from department b where b.deptid = a.deptid)
from employee a where ....

Within a form, you can use DLookup to do this
DLookup("deptname", "dept", "deptid = &{deptid})

(The curly brackets are incorrect, they should be square brackets, but I don't know how to display those in this forum.)

Then, for each row returned on the form from employee, the department name from department would be looked up.

However, if possible just do a join in the SQL; this will likely be faster, and more portable if you move from access to another grand of database. DLookup is not portable.

Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Thu Apr 25th 2024, 10:50 AM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » The DU Lounge Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC