HelloWorld
HelloWorld

Reputation: 283

Access 2010 DLookUp

Working with MS Access for the first time and coming across a few problems if someone could please point me in the right direction.

So I'm doing a mock database (so it looks silly) just to learn the ins and outs and need some help with DLookUp at the moment.

My database has two tables, with the following fields: C_ID the PK in Courses and FK in Student

tblCourse: C_ID, Title, Subject                              
tblStudent: S_ID, C_ID, Name, EnrollDATE  

As I said this is just for testing/learning. So what I want is to have a filter that gives me a list of C_ID's based on which EnrollDates are NULL.

so filter is:

Expr1: DLookUp("[tblStudent]![C_ID]","tblStudent","isNull([tblStudent]![EnrollDATE])")

I have also tried with the criteria being

 [tblStudent]![EnrollDATE] = Null

Currently I get just blank fields returned. Any help is greatly appreciated, and please ask me to elaborate if my explanation is off.

Thank You!

Upvotes: 2

Views: 1638

Answers (1)

Christian Specht
Christian Specht

Reputation: 36451

The correct syntax looks like this:

DLookup("C_ID", "tblStudent", "EnrollDate is null")
  1. You don't need to include the table name when you specify the columns
  2. In Access, you check for Null by using xxx is null or xxx is not null

Note that DLookup only returns one value (if the criteria matches more than one row, the value is taken from any row), so you can't use it to get a list of C_IDs back.


EDIT:
What you actually want to do is select data from one table, and filter that based on data from the other table, correct?
Like, selecting all courses where at least one student has an empty EnrollDATE?

If yes, you don't need the DLookup at all, there are two different ways how to do that:

1) With a sub-select:

select *
from tblCourse
where C_ID in
(
    select C_ID
    from tblStudents
    where EnrollDATE is null
)

2) By joining the tables:

select tblCourse.*
from tblCourse
inner join tblStudent on tblCourse.C_ID = tblStudent.C_ID
where tblStudent.EnrollDATE is null

This is SQL, so you need to switch to SQL View in your query in Access.

Upvotes: 1

Related Questions