Solved DCOUNT() ISSUE (1 Viewer)

Ashfaque

Student
Local time
Today, 06:29
Joined
Sep 6, 2004
Messages
894
Hi,

I have mainform called F_Project with subform F_ProjAssigneeDetails - one-to-many relation

The key field in main form is ProjNum which is relevant with subform as well. When we enter new project in main form, we adds number employee to that particular projects.

I just want to count number of staff assigned on a particular projects. I tried it with Dcount but the X is producing 0 only where as there are 3 active employees assigned on that project. my AssigneeActive is check mark field on subform.

Following code is triggering thru a combo placed on main form.

Code:
Dim X As Integer
X = DCount("*", "T_ProjAssigneeDetails", "ProjNum = 'ProjNum' and 'Me!F_ProjAssigneeDetails!AssigneeActive.value= true'")
Me!F_ProjAssigneeDetails!TotAssignedStaff = " " & X

No error but not counting numbers.

Any help shall be appreciated..
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 01:59
Joined
Jul 21, 2014
Messages
2,277
Without more details, I suspect you should be concatenating your values in to your criteria expression:
Code:
Dim X As Integer
X = DCount("*", "T_ProjAssigneeDetails", "ProjNum = '" & Me.ProjNum & "' and AssigneeActive = " & Me.F_ProjAssigneeDetails.Form.AssigneeActive)
' ...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:59
Joined
May 7, 2009
Messages
19,237
or
Code:
Dim X As Integer
X = DCount("*", "T_ProjAssigneeDetails", "ProjNum = '" & Me.ProjNum & "' and AssigneeActive = -1")
 

cheekybuddha

AWF VIP
Local time
Today, 01:59
Joined
Jul 21, 2014
Messages
2,277
Good point Arnel, you only need to count the active assignees. (y)
 

Ashfaque

Student
Local time
Today, 06:29
Joined
Sep 6, 2004
Messages
894
or
Code:
Dim X As Integer
X = DCount("*", "T_ProjAssigneeDetails", "ProjNum = '" & Me.ProjNum & "' and AssigneeActive = -1")
Thanks Arnel,

I tried the both way you explained but still X is producing 0 value.
Or do you suggest I should place my text box"TotAssignedStaff" on main form instead of subform to get X value.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 19:59
Joined
Feb 28, 2001
Messages
27,179
What is the data type of ProjNum? If it is numeric, that syntax isn't going to work because in that context, you are comparing a quoted text string to a numeric value. That won't fly.

Code:
X = DCount("*", "T_ProjAssigneeDetails", "( ProjNum = " & ProjNum & ") and " & Me!F_ProjAssigneeDetails!AssigneeActive )

1. Syntax for numeric "ProjNum" case
2. Don't have to compare a "TRUE" value to anything when in a conditional expression. Remember that your criteria will be evaluated as separate T/F values. So the left half is T/F based on ProjNum having the specific value and the right half is T/F based on ... itself, because it is a Boolean.
 

Ashfaque

Student
Local time
Today, 06:29
Joined
Sep 6, 2004
Messages
894
What is the data type of ProjNum? If it is numeric, that syntax isn't going to work because in that context, you are comparing a quoted text string to a numeric value. That won't fly.

Code:
X = DCount("*", "T_ProjAssigneeDetails", "( ProjNum = " & ProjNum & ") and " & Me!F_ProjAssigneeDetails!AssigneeActive )

1. Syntax for numeric "ProjNum" case
2. Don't have to compare a "TRUE" value to anything when in a conditional expression. Remember that your criteria will be evaluated as separate T/F values. So the left half is T/F based on ProjNum having the specific value and the right half is T/F based on ... itself, because it is a Boolean.
ProjNum is Text data type.

Your above line produces Run-time error 2471 - The expression your entered as query parameter has produced this error: 'PRJ'

The string value is actually PRJ/CNRT/21/00001, PRJ/CNRT/21/00002 etc....
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:59
Joined
May 7, 2009
Messages
19,237
post the structure of T_projAssigneeDetails table.
 

Ashfaque

Student
Local time
Today, 06:29
Joined
Sep 6, 2004
Messages
894
Thanks Arnel,

My tables are on SQL server and linked in Access FE.
 

Attachments

  • MainTable Structure.jpg
    MainTable Structure.jpg
    61 KB · Views: 520
  • AssigneeTable Structure.jpg
    AssigneeTable Structure.jpg
    64.4 KB · Views: 499

Ashfaque

Student
Local time
Today, 06:29
Joined
Sep 6, 2004
Messages
894
Attached shows the data in both table
 

Attachments

  • MainTable Data.jpg
    MainTable Data.jpg
    32.8 KB · Views: 455
  • AssigneeTable Data.jpg
    AssigneeTable Data.jpg
    53.3 KB · Views: 520

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:59
Joined
May 7, 2009
Messages
19,237
we go back to post#1 formula.
projNum is in the Combo?
what is the rowSource of the combo and it's Bound Column?
 

Ashfaque

Student
Local time
Today, 06:29
Joined
Sep 6, 2004
Messages
894
we go back to post#1 formula.
projNum is in the Combo?
what is the rowSource of the combo and it's Bound Column?
This is rowsource of combo on main form:

SELECT [T_ProjectBaseContracts].[ProjNum] FROM T_ProjectBaseContracts ORDER BY [ProjNum];
 

Attachments

  • RowSource.jpg
    RowSource.jpg
    51.7 KB · Views: 505

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:59
Joined
May 7, 2009
Messages
19,237
so you need to use the Combobox Name:

Dim X As Integer
X = DCount("*", "T_ProjAssigneeDetails", "ProjNum = '" & Me!theComboboxNameHere & "' and AssigneeActive = -1")
 

Ashfaque

Student
Local time
Today, 06:29
Joined
Sep 6, 2004
Messages
894
so you need to use the Combobox Name:

Dim X As Integer
X = DCount("*", "T_ProjAssigneeDetails", "ProjNum = '" & Me!theComboboxNameHere & "' and AssigneeActive = -1")

Tried that way in the beginning. Please see the pic. I placed cursor to know the x value...it is still zero.
 

Attachments

  • Still Not Geting Value.jpg
    Still Not Geting Value.jpg
    74.4 KB · Views: 407

Ashfaque

Student
Local time
Today, 06:29
Joined
Sep 6, 2004
Messages
894
I just played with your code particulary with quotes like below:
X = DCount("*", "T_ProjAssigneeDetails", "ProjNum = '" & Me!CboSearchProj.Column(0) & "'")
and half part of worked. But addtional criteria is still pending.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:59
Joined
May 7, 2009
Messages
19,237
is any record for that projnum has AssigneeActive Checked?
can you try the other fields:

X = DCount("*", "T_ProjAssigneeDetails", "ProjNum = '" & Me!CboSearchProj & "' And ((ProjAssigneeName Is Null)=False)")
 

Ashfaque

Student
Local time
Today, 06:29
Joined
Sep 6, 2004
Messages
894
is any record for that projnum has AssigneeActive Checked?
can you try the other fields:

X = DCount("*", "T_ProjAssigneeDetails", "ProjNum = '" & Me!CboSearchProj & "' And ((ProjAssigneeName Is Null)=False)")
2 records are checked and one record unchecked
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:59
Joined
May 7, 2009
Messages
19,237
does ProjNum field has a Lookup?
can you post just the T_ProjAssigneeDetails.
 

Users who are viewing this thread

Top Bottom