473,403 Members | 2,270 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,403 software developers and data experts.

Problem with record counts and "Invalid Use of Null"

121 100+
I have a simple question, but I can't seem to find the answer.


I have this code to count the number of records that pass through a set of processes:

It counts how many records go through INPUT, VALIDATED, ERRORS

This is the code to get the numbers:
Expand|Select|Wrap|Line Numbers
  1. Function Val_Message()
  2.  
  3. Dim Inp_Count As Integer
  4. Dim Val_Count As Integer
  5. Dim ERR_Count As Integer
  6. Dim VAL_Response As Integer
  7.  
  8. DoCmd.OpenQuery "CLR_16001 - Clear Status_Counts Table", acViewNormal, acEdit
  9. DoCmd.OpenQuery "STAT_10001 - Count Imp Records", acViewNormal, acEdit
  10. DoCmd.OpenQuery "STAT_10002 - Count Val Records", acViewNormal, acEdit
  11. DoCmd.OpenQuery "STAT_10003 - Count Err Records", acViewNormal, acEdit
  12.  
  13.  
  14. Inp_Count = DLookup("[RECORD_COUNT]", "[STATUS_COUNTS]", "[COUNT_TYPE]='INPUT'")
  15. Val_Count = DLookup("[RECORD_COUNT]", "[STATUS_COUNTS]", "[COUNT_TYPE]='VALIDATED'")
  16. ERR_Count = DLookup("[RECORD_COUNT]", "[STATUS_COUNTS]", "[COUNT_TYPE]='ERRORS'")
  17.  
  18.     If Inp_Count = "" Then
  19.     Inp_Count = 0
  20.     End If
  21.  
  22.     If Val_Count = "" Then
  23.     Val_Count = 0
  24.     End If
  25.  
  26.     If ERR_Count = "" Then
  27.     ERR_Count = 0
  28.     End If
  29.  
  30. If ERR_Count = 0 Then
  31.         VAL_Response = MsgBox("All Records Passed Validation." & Chr(10) & Inp_Count & " Records were Loaded" & Chr(10) & Val_Count & " Records Passed Validation" & Chr(10) & "The records are now ready to be processed", vbOKOnly + vbApplicationModal + vbInformation, "Validation Complete")
  32.         DoCmd.RunMacro "RUN_Validate_2", , ""
  33.  
  34. Else
  35.     VAL_Response = MsgBox("All Records Have Been VALD_CT." & Chr(10) & Inp_Count & " Records were Loaded" & Chr(10) & Val_Count & " Records Passed Validation" & Chr(10) & ERR_Count & " Records Failed Validation" & Chr(10) & "Would you like to complete review the error records before proceeding?", vbYesNo + vbApplicationModal + vbQuestion, "Validation Complete")
  36.  
  37.     If VAL_Response = vbYes Then
  38.         DoCmd.OpenForm "Review Current Error Records", acNormal, "", "", , acNormal
  39.     Else
  40.         Call ERR_OVERRD_Message
  41.         DoCmd.RunMacro "RUN_Validate_2", , ""
  42.  
  43.     End If
  44. End If
  45. End Function

As you can see, I call on three queries to get those numbers. The queries each do a count of the number of records, and adds that and a description (i.e. VALIDATED, INPUT, etc.) to a Table (STATUS_COUNTS). The Dlookups you see in the code.

The queries look like this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO STATUS_COUNTS ( RECORD_COUNT, COUNT_TYPE )
  2. SELECT Count(ETL_TBL.INPT_IND) AS CountOfSTTS_INPT, "INPUT" AS expr1
  3. FROM ETL_TBL
  4. HAVING (((Count(ETL_TBL.INPT_IND))=Yes));
What happens is that if no records are found in any of these processes, a record doesn't get written with [COUNT_TYPE], and so I get an "Invalid use of Null" error.

Thanks for any help I can get.
Apr 19 '07 #1
12 3037
JHNielson
121 100+
One other thing, one idea I had to address this is change the queries for Append Queries to Update queries, and then simply update the fields in the table by Matching the descriptions, - that way there would already be a record with "Validated" and a value of 0 in the table, unless it got updated. But I can't seem to get an update query to count based on criteria.

Thanks again
Apr 19 '07 #2
ADezii
8,834 Expert 8TB
I have a simple question, but I can't seem to find the answer.


I have this code to count the number of records that pass through a set of processes:

It counts how many records go through INPUT, VALIDATED, ERRORS

This is the code to get the numbers:
Expand|Select|Wrap|Line Numbers
  1. Function Val_Message()
  2.  
  3. Dim Inp_Count As Integer
  4. Dim Val_Count As Integer
  5. Dim ERR_Count As Integer
  6. Dim VAL_Response As Integer
  7.  
  8. DoCmd.OpenQuery "CLR_16001 - Clear Status_Counts Table", acViewNormal, acEdit
  9. DoCmd.OpenQuery "STAT_10001 - Count Imp Records", acViewNormal, acEdit
  10. DoCmd.OpenQuery "STAT_10002 - Count Val Records", acViewNormal, acEdit
  11. DoCmd.OpenQuery "STAT_10003 - Count Err Records", acViewNormal, acEdit
  12.  
  13.  
  14. Inp_Count = DLookup("[RECORD_COUNT]", "[STATUS_COUNTS]", "[COUNT_TYPE]='INPUT'")
  15. Val_Count = DLookup("[RECORD_COUNT]", "[STATUS_COUNTS]", "[COUNT_TYPE]='VALIDATED'")
  16. ERR_Count = DLookup("[RECORD_COUNT]", "[STATUS_COUNTS]", "[COUNT_TYPE]='ERRORS'")
  17.  
  18.     If Inp_Count = "" Then
  19.     Inp_Count = 0
  20.     End If
  21.  
  22.     If Val_Count = "" Then
  23.     Val_Count = 0
  24.     End If
  25.  
  26.     If ERR_Count = "" Then
  27.     ERR_Count = 0
  28.     End If
  29.  
  30. If ERR_Count = 0 Then
  31.         VAL_Response = MsgBox("All Records Passed Validation." & Chr(10) & Inp_Count & " Records were Loaded" & Chr(10) & Val_Count & " Records Passed Validation" & Chr(10) & "The records are now ready to be processed", vbOKOnly + vbApplicationModal + vbInformation, "Validation Complete")
  32.         DoCmd.RunMacro "RUN_Validate_2", , ""
  33.  
  34. Else
  35.     VAL_Response = MsgBox("All Records Have Been VALD_CT." & Chr(10) & Inp_Count & " Records were Loaded" & Chr(10) & Val_Count & " Records Passed Validation" & Chr(10) & ERR_Count & " Records Failed Validation" & Chr(10) & "Would you like to complete review the error records before proceeding?", vbYesNo + vbApplicationModal + vbQuestion, "Validation Complete")
  36.  
  37.     If VAL_Response = vbYes Then
  38.         DoCmd.OpenForm "Review Current Error Records", acNormal, "", "", , acNormal
  39.     Else
  40.         Call ERR_OVERRD_Message
  41.         DoCmd.RunMacro "RUN_Validate_2", , ""
  42.  
  43.     End If
  44. End If
  45. End Function

As you can see, I call on three queries to get those numbers. The queries each do a count of the number of records, and adds that and a description (i.e. VALIDATED, INPUT, etc.) to a Table (STATUS_COUNTS). The Dlookups you see in the code.

The queries look like this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO STATUS_COUNTS ( RECORD_COUNT, COUNT_TYPE )
  2. SELECT Count(ETL_TBL.INPT_IND) AS CountOfSTTS_INPT, "INPUT" AS expr1
  3. FROM ETL_TBL
  4. HAVING (((Count(ETL_TBL.INPT_IND))=Yes));
What happens is that if no records are found in any of these processes, a record doesn't get written with [COUNT_TYPE], and so I get an "Invalid use of Null" error.

Thanks for any help I can get.
Try this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO STATUS_COUNTS ( RECORD_COUNT, Nz(COUNT_TYPE) AS COUNT_TYPE_NEW  )
  2. SELECT Count(ETL_TBL.INPT_IND) AS CountOfSTTS_INPT, "INPUT" AS expr1
  3. FROM ETL_TBL
  4. HAVING (((Count(ETL_TBL.INPT_IND))=Yes));
Apr 19 '07 #3
JHNielson
121 100+
Try this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO STATUS_COUNTS ( RECORD_COUNT, Nz(COUNT_TYPE) AS COUNT_TYPE_NEW  )
  2. SELECT Count(ETL_TBL.INPT_IND) AS CountOfSTTS_INPT, "INPUT" AS expr1
  3. FROM ETL_TBL
  4. HAVING (((Count(ETL_TBL.INPT_IND))=Yes));

thank for the help. Sorry, but I get a:

Syntax Error in INSERT INTO Statement

I tried to trouble shoot it, but it seems to have a prblem wiht the ...as COUNT TYPRE.... part or the ....Nz... part.
Apr 19 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
Try this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO STATUS_COUNTS ( RECORD_COUNT, COUNT_TYPE ) 
  2. SELECT nz(Count(ETL_TBL.INPT_IND),0) AS CountOfSTTS_INPT, "INPUT" AS expr1
  3. FROM ETL_TBL
  4. WHERE ETL_TBL.INPT_IND = -1;
  5.  
Apr 19 '07 #5
ADezii
8,834 Expert 8TB
thank for the help. Sorry, but I get a:

Syntax Error in INSERT INTO Statement

I tried to trouble shoot it, but it seems to have a prblem wiht the ...as COUNT TYPRE.... part or the ....Nz... part.
Did you use this exact syntax?
Expand|Select|Wrap|Line Numbers
  1. Nz(COUNT_TYPE) AS COUNT_TYPE_NEW 
Apr 19 '07 #6
JHNielson
121 100+
Did you use this exact syntax?
Expand|Select|Wrap|Line Numbers
  1. Nz(COUNT_TYPE) AS COUNT_TYPE_NEW 

Yes I copied the SQL in directly. Here it is:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO STATUS_COUNTS ( RECORD_COUNT, Nz(COUNT_TYPE) AS COUNT_TYPE_NEW  )
  2. SELECT Count(ETL_TBL.INPT_IND) AS CountOfSTTS_INPT, "INPUT" AS expr1
  3. FROM ETL_TBL
  4. HAVING (((Count(ETL_TBL.INPT_IND))=Yes));
I;m not positive what is causing the problem, it's just that when I get the error and click ok - it sticks the cursor right between the Nz and (. SO I assume that is the source of the problem.


Thanks for all your help.
Apr 19 '07 #7
JHNielson
121 100+
Would it be easier to use the VB code for Recordcount?
I'm not sure what the easiest way to do this is...

Thanks
Apr 19 '07 #8
MMcCarthy
14,534 Expert Mod 8TB
Would it be easier to use the VB code for Recordcount?
I'm not sure what the easiest way to do this is...

Thanks
What happened when you tried my suggestion?
Apr 19 '07 #9
JHNielson
121 100+
I hate to be a pest but I have been back and forth trying to solve this.

I got this query to find the number of records:

Expand|Select|Wrap|Line Numbers
  1. SELECT ([STAT_01003 - Count Err Records].CountOfERR_DESC)-([STAT_01001 - Count Imp Records].Count1) AS Rec_Count, "Validated" AS Rec_Field
  2. FROM [STAT_01001 - Count Imp Records], [STAT_01003 - Count Err Records];
  3.  
And then I use this query to update the table [STATUS_COUNTS] with that number/ I got it so that it returns a 0 using the NZ method mentioned earlier. But, I still get a prompt for a value for [STG_IMPT] if it is null.

Expand|Select|Wrap|Line Numbers
  1. UPDATE STATUS_COUNTS SET STATUS_COUNTS.VAL_COUNT = Format(nz([STAT_02002 - Count Numberof Validated].[Rec_Count]),0);
Thanksfor any help anyone can provide with either fixing this process or using the VB Record count method. I'm open to any suggestions. Thanks.
Apr 19 '07 #10
JHNielson
121 100+
Can anybody provide some help? I have racked my brain and can't seem to solve tis problem.
Apr 20 '07 #11
MMcCarthy
14,534 Expert Mod 8TB
Can anybody provide some help? I have racked my brain and can't seem to solve tis problem.
As you haven't answered any of my posts I don't know what happened when you tried the code I provided.
Apr 20 '07 #12
NeoPa
32,556 Expert Mod 16PB
JHNielson,
Please respond to all attempts to help you in your thread. To fail to respond is actually an exhibition of very poor manners and our members are likely to treat your requests with disdain unless you treat them with at least a basic level of respect.

There is an answer to this but I doubt you'll see it if you fail to communicate in an acceptable way.

MODERATOR.

As you haven't answered any of my posts I don't know what happened when you tried the code I provided.
Mary,
What would have happened is that no record was produced for that WHERE clause so no record would be added. Essentially an empty recordset. But don't worry - I get the point you were making.
Apr 25 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: TS | last post by:
Hi, i have a problem validating xml against schema. I used http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx validator and it says it is fine. Can you tell me why this doesn't work? ...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
7
by: Dica | last post by:
i've used the sample code from msdn to create an encyption/decryption assembly as found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp i'm...
9
by: D. Shane Fowlkes | last post by:
I'm using SQL Server 2000 and on my page, I'm simply creating a SQLDataReader and filling in Labels with the retrieved (single) record. However, how can I prevent from getting errors when a field...
2
by: Dabbler | last post by:
In my Registrant FormView I have a DropDownList which loads data from a secondary SqlDataSource "sdsOfficeParks". I need the user to select an office park but save the selected value in the...
5
by: Stewart | last post by:
Hi there, I would like to calculate a person's age in years (between 2 dates). I am using the following function for this calculation (source: http://www.mvps.org/access/datetime/date0001.htm)...
4
by: MarkusR | last post by:
If I run the stored proc in the Query Analyzer this works and I get the expected result set back. However when I run it in my application I get a results set of one row but when I try to access the...
2
by: Bill_DBA | last post by:
I have the following stored procedure that is called from the source of a transformation in a DTS package. The first parameter turns on PRINT debug messages. The second, when equals 1, turns on the...
9
by: 200dogz | last post by:
Hi guys, I want to have a button which opens up a new window when pressed. <asp:Button ID="Button1" runat="server" Text="Open new window" /> ... Button1.Attributes.Add("OnClick",
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.