DCount with two tables

G

Guest

I have two tables:
Student table with fields of: StudentID and Status (values of Current, New,
Past) plus other fields.
Activity table with fields of: StudentID and Activity plus other fields.

The tables have a one (student table) to many (Activity table) relationship

I have a form where the user selects (using check boxes) a status
(ckCurrent, ckNew or ckPast) and then clicks on a command button which will
produce a report. In the on-click event of the command button I want to use
Dcount to insure that there are entries in the activity table for students
with the selected status? Can this be done, where two tables are involved?

Example. If the user selects “ckPast†and there are no entries in the
activity table for students with a status of Past, I want to display a
message that there are no students for the selected status.

Any help would be appreciated.
Thanks
 
G

Guest

You can't DCount multiple tables at once, but you can DCount a query that
combines multiple tables.
Write a query that returns StudentId, Status and Activity, then use the
query in your DCount function
 
G

Guest

Thanks Chris,

I created the query and have the following code in my on-click event:
-------------
strcriteria = "([Status] = 'Current' And [ckStatusCurrent] = -1) Or " & _
"([Status] = 'New' And [ckStatusNew] = -1) Or " & _
"([Status] = 'Past' And [ckStatusPast] = -1)"


intx = DCount("[StudentID]", "ActivityStatusQuery", strcriteria)
--------------
I get the following error when exceuiting the DCount line:

The expression you entered has a query parameter produced the following
error: The object dosen't contain the automation object 'StudentID'

Any ideas???

Thanks
 
G

Guest

OK, Its saying that you don't have StudentID in your "ActivityStatusQuery"
query.
If it looks like you do have such a field, check the field in the base table
and make sure it doesn't have a caption set. Access tends to propagate these
or not at inconvenient times.

Phil said:
Thanks Chris,

I created the query and have the following code in my on-click event:
-------------
strcriteria = "([Status] = 'Current' And [ckStatusCurrent] = -1) Or " & _
"([Status] = 'New' And [ckStatusNew] = -1) Or " & _
"([Status] = 'Past' And [ckStatusPast] = -1)"


intx = DCount("[StudentID]", "ActivityStatusQuery", strcriteria)
--------------
I get the following error when exceuiting the DCount line:

The expression you entered has a query parameter produced the following
error: The object dosen't contain the automation object 'StudentID'

Any ideas???

Thanks

ChrisJ said:
You can't DCount multiple tables at once, but you can DCount a query that
combines multiple tables.
Write a query that returns StudentId, Status and Activity, then use the
query in your DCount function
 
G

Guest

Thanks again Chris

My base tables looked fine, but when I checked the field names in my query
the StudentID field was strange, so I deleted the field and re-added it and
now everything works great.

Thanks for your help

ChrisJ said:
OK, Its saying that you don't have StudentID in your "ActivityStatusQuery"
query.
If it looks like you do have such a field, check the field in the base table
and make sure it doesn't have a caption set. Access tends to propagate these
or not at inconvenient times.

Phil said:
Thanks Chris,

I created the query and have the following code in my on-click event:
-------------
strcriteria = "([Status] = 'Current' And [ckStatusCurrent] = -1) Or " & _
"([Status] = 'New' And [ckStatusNew] = -1) Or " & _
"([Status] = 'Past' And [ckStatusPast] = -1)"


intx = DCount("[StudentID]", "ActivityStatusQuery", strcriteria)
--------------
I get the following error when exceuiting the DCount line:

The expression you entered has a query parameter produced the following
error: The object dosen't contain the automation object 'StudentID'

Any ideas???

Thanks

ChrisJ said:
You can't DCount multiple tables at once, but you can DCount a query that
combines multiple tables.
Write a query that returns StudentId, Status and Activity, then use the
query in your DCount function

:

I have two tables:
Student table with fields of: StudentID and Status (values of Current, New,
Past) plus other fields.
Activity table with fields of: StudentID and Activity plus other fields.

The tables have a one (student table) to many (Activity table) relationship

I have a form where the user selects (using check boxes) a status
(ckCurrent, ckNew or ckPast) and then clicks on a command button which will
produce a report. In the on-click event of the command button I want to use
Dcount to insure that there are entries in the activity table for students
with the selected status? Can this be done, where two tables are involved?

Example. If the user selects “ckPast†and there are no entries in the
activity table for students with a status of Past, I want to display a
message that there are no students for the selected status.

Any help would be appreciated.
Thanks
 

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

Similar Threads

DCount problem 3
Type mis match in expression on a form 2
OpenRecordset type mismatch 3
Setting up tables for grades 17
Activity entry form 3
Query problem 7
Form Is Read Only 2
Junction Tables 6

Top