473,414 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Count fields that are not null

Kev
Hello all,
I have an Access 2003 database running on an XP network.
I have a subform containing a 28 day roster - shift1 to shift28.
I need to total the shifts for each employee and am unsure of how to
do thid.
Each record has 1 EmployeeNumber, 28 shift fields, and 1 shiftTotal
field and 1 HoursTotal field.
I investigated the Count function but I think this Counts on the basis
of a field (Column) not a Record.
Does anyone have an idea how I should tackle this problem or am I on
the wrong track altogether?
Regards
Kevin

Mar 20 '07 #1
5 8730
On Mar 19, 11:10 pm, "Kev" <kevin.vaug...@nhw.hume.org.auwrote:
Hello all,
I have an Access 2003 database running on an XP network.
I have a subform containing a 28 day roster - shift1 to shift28.
I need to total the shifts for each employee and am unsure of how to
do thid.
Each record has 1 EmployeeNumber, 28 shift fields, and 1 shiftTotal
field and 1 HoursTotal field.
I investigated the Count function but I think this Counts on the basis
of a field (Column) not a Record.
Does anyone have an idea how I should tackle this problem or am I on
the wrong track altogether?
Regards
Kevin
I think you want something like sum (iif (shift1, 1, 0). This assumes
shift1 is boolean of course. Count won't work as you found out.

Mar 20 '07 #2
Kev

I think you want something like sum (iif (shift1, 1, 0). This assumes
shift1 is boolean of course. Count won't work as you found out.
Hello All,
Unfortunately Eng, Shift1 through to Shift28 are all text, not
boolean.
I still do not understand how your solution would count or sum the
shifts for a record (datasheet row). Isn't your solution summing all
the non nulls for the shift1 field (the column).
Sorry if I'm missing something which I obviously am.
I was thinking of something like the function below in the afterUpdate
event procedure but it seems like a lot of code and processing each
time someone makes a change:
Does anyone know of a more efficient method? I've never used the
Select Case statement before, would this be appropriate or is there a
predefined function for doing this?

Regards
Kevin

Public Function ShiftCounter()
Dim shiftCount As Long
shiftCount = 0
If (IsNull(Shift1)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift2)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift3)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift4)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift5)) Then
Else
shiftCount = shiftCount + 1
End If
Me![ShiftTotal] = shiftCount

End Function

Mar 20 '07 #3
On Mar 20, 3:52 pm, "Kev" <kevin.vaug...@nhw.hume.org.auwrote:
I think you want something like sum (iif (shift1, 1, 0). This assumes
shift1 is boolean of course. Count won't work as you found out.

Hello All,
Unfortunately Eng, Shift1 through to Shift28 are all text, not
boolean.
I still do not understand how your solution would count or sum the
shifts for a record (datasheet row). Isn't your solution summing all
the non nulls for the shift1 field (the column).
Sorry if I'm missing something which I obviously am.
I was thinking of something like the function below in the afterUpdate
event procedure but it seems like a lot of code and processing each
time someone makes a change:
Does anyone know of a more efficient method? I've never used the
Select Case statement before, would this be appropriate or is there a
predefined function for doing this?

Regards
Kevin

Public Function ShiftCounter()
Dim shiftCount As Long
shiftCount = 0
If (IsNull(Shift1)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift2)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift3)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift4)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift5)) Then
Else
shiftCount = shiftCount + 1
End If
Me![ShiftTotal] = shiftCount

End Function
Have you thought about arranging your data differently? I would have
defined a separate table called "Shift" with field to indicate the
shift in it. Its foreign key is to the employees table. The fact
that the record is in the Shift table for the employee means that
employee works that shift. Then you can join and count directly.

Mar 21 '07 #4
On Mar 20, 3:52 pm, "Kev" <kevin.vaug...@nhw.hume.org.auwrote:
I think you want something like sum (iif (shift1, 1, 0). This assumes
shift1 is boolean of course. Count won't work as you found out.

Hello All,
Unfortunately Eng, Shift1 through to Shift28 are all text, not
boolean.
I still do not understand how your solution would count or sum the
shifts for a record (datasheet row). Isn't your solution summing all
the non nulls for the shift1 field (the column).
Sorry if I'm missing something which I obviously am.
I was thinking of something like the function below in the afterUpdate
event procedure but it seems like a lot of code and processing each
time someone makes a change:
Does anyone know of a more efficient method? I've never used the
Select Case statement before, would this be appropriate or is there a
predefined function for doing this?

Regards
Kevin

Public Function ShiftCounter()
Dim shiftCount As Long
shiftCount = 0
If (IsNull(Shift1)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift2)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift3)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift4)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift5)) Then
Else
shiftCount = shiftCount + 1
End If
Me![ShiftTotal] = shiftCount

End Function
You can put that logic in a query.

shiftCount: iif(isnull(shift1),0,1) + iif (isnull(Shift2), 0, 1) + ...
+ iif (isnull(Shift28),0,1)

Mar 21 '07 #5
Kev
On Mar 21, 7:17 pm, eng...@ridesoft.com wrote:
On Mar 20, 3:52 pm, "Kev" <kevin.vaug...@nhw.hume.org.auwrote:
I think you want something like sum (iif (shift1, 1, 0). This assumes
shift1 is boolean of course. Count won't work as you found out.
Hello All,
Unfortunately Eng, Shift1 through to Shift28 are all text, not
boolean.
I still do not understand how your solution would count or sum the
shifts for a record (datasheet row). Isn't your solution summing all
the non nulls for the shift1 field (the column).
Sorry if I'm missing something which I obviously am.
I was thinking of something like the function below in the afterUpdate
event procedure but it seems like a lot of code and processing each
time someone makes a change:
Does anyone know of a more efficient method? I've never used the
Select Case statement before, would this be appropriate or is there a
predefined function for doing this?
Regards
Kevin
Public Function ShiftCounter()
Dim shiftCount As Long
shiftCount = 0
If (IsNull(Shift1)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift2)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift3)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift4)) Then
Else
shiftCount = shiftCount + 1
End If
If (IsNull(Shift5)) Then
Else
shiftCount = shiftCount + 1
End If
Me![ShiftTotal] = shiftCount
End Function

You can put that logic in a query.

shiftCount: iif(isnull(shift1),0,1) + iif (isnull(Shift2), 0, 1) + ...
+ iif (isnull(Shift28),0,1)

Thanks Eng,
This works really well and its fast and simple.
Really appreciate it, Thank you
Kevin

Mar 22 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: venkata | last post by:
hi I have a situation like this a field in a table has the following values of capacitors c1,c2,c5-c10 can I count the number of so that I get the result as 8 if so please help me...
1
by: Phil Kershaw | last post by:
Hi All, Can anyone help me with a problem that has been driving me mad. I have a table with 10 fields in it for staff to enter their initials to register a vote. I need to count the fields that...
1
by: RiesbeckP | last post by:
Hi All, I have a DB where there are customer numbers and a few other fields. I want to be able to pull all of the null records for a particular field as well as all the other customer numbers...
1
by: Dan | last post by:
I am linking two queries in Access. One has data in several fields such as: Name, Year, Amount, CumTotal1, CumTotal2 where the cumulative total fields are two subqueries generating cumulative...
1
by: griemer | last post by:
I have a database like this id, field1,field2,field3,field4,field5 Database contains 100 rows, some rows have no fields filled, some 1field , some 2 fields etc. How would i count the...
3
by: cdownload | last post by:
I have 7 fields to key to on a form. Is there a way to count the number fields that have for example, a value greater than zero?
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
3
by: Jim | last post by:
How would I write a query to count the number of instances where a the PREP field is NULL and when it is not null. I know how to do it seperately, can I get the numbers in the same query. I want...
1
by: dud10 | last post by:
Hi All, I´m having a problem with count of null values fields and indexes... I have a table (tb_Propose) with around 8 million lines. A field Dt_flag -- Datetime An index Ix_Dt_flag,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.