Access 2010 DLookUp

感情迁移 提交于 2020-01-04 17:54:37

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/11196724/access-2010-dlookup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!