I am trying to build a db to report the deficiencies/strengths of security. We have about 1000 criterion that we base these on. I am trying to set it up to where we can specify which criteria they are deficient in, and it will report the total number of deficiencies that section has. i have tried to do this with a yes/no field, and code that looks a little like this: - Sum(([a1000]+[a1001]+[a1003]+[a1002]+[a1004]+[a1005])*-1)
in order to calculate the total number, but you can see how after even 20 feilds in one table this would get unweildy, let alone across several different tables, because of the 255 field limit that 'MS Access' has.
Is there anything that I am missing? How can I optimize my calculation and db to make it more functional and less error prone. I am used to debugging in c/c++, but SQL is kind of killing me with all of its rules.
5 1364
Hopefully I interpreted your request correctly, but here goes. I created a Generic Function for you which will enable you to list the Yes/No Fields by Name in a Table Name passed to the Function, calculates the Number of Yes(s) in each Yes/No Field, then calculates the Percentage of Yes(s) based on the Total Number of Records in the Table. I'll post the Function Definition below, an example of a Sample Call to the Function, and subsequent OUTPUT based on Sample Data (20 Records in tblTest with 15 Fields, 10 of which were Yes/No Type). - Function Code:
- Public Function fCountYesNos(strTableName As String)
-
Dim MyDB As DAO.Database
-
Dim rst As DAO.Recordset
-
Dim intNumOfFields As Integer
-
Dim intFldCtr As Integer
-
Dim lngNumOfRecs As Long
-
Dim intNumOfYess As Integer
-
Const conYESNOField As Byte = 1
-
-
Set MyDB = CurrentDb
-
Set rst = MyDB.OpenRecordset(strTableName, dbOpenSnapshot)
-
-
rst.MoveLast: rst.MoveFirst
-
-
intNumOfFields = rst.Fields.Count
-
lngNumOfRecs = rst.RecordCount
-
-
Debug.Print "Field Name", "Yes(s)", "Percent"
-
Debug.Print "--------------------------------------------"
-
-
With rst
-
For intFldCtr = 0 To intNumOfFields - 1 'Fields Collection indexed at 0
-
If .Fields(intFldCtr).Type = conYESNOField Then 'Sorry, Yes/No Field Types only
-
intNumOfYess = DCount("*", strTableName, .Fields(intFldCtr).Name & " = True")
-
Debug.Print .Fields(intFldCtr).Name, intNumOfYess, Format(intNumOfYess / lngNumOfRecs, "Percent")
-
End If
-
Next
-
End With
-
-
rst.Close
-
Set rst = Nothing
-
End Function
- Sample Call to Function, passing a Table Name:
- Call fCountYesNos("tblTest")
- OUTPUT based on Sample Data:
- Field Name Yes(s) Percent
-
--------------------------------------------
-
Field1 0 0.00%
-
Field2 5 25.00%
-
Field3 3 15.00%
-
Field4 2 10.00%
-
Field5 5 25.00%
-
Field6 2 10.00%
-
Field7 4 20.00%
-
Field8 3 15.00%
-
Field9 3 15.00%
-
Field10 4 20.00%
NeoPa 32,556
Expert Mod 16PB
I would suggest you look at the design of your database to see how you could get the RDBMS (Access in this case) to work for you. A table structure where the table had records for each question within each situation would seem to fit your situation very much better than what you appear to be using now.
From that position your calculations would be a cinch.
I think that gets me about 3/4 of the way there. In the report, I am querying the tables with the deficiencies, and putting that information along side the section information. I am doing it this way in order to print it out and give it to my boss so she can read it and know what section needs the most work. Also, when there was only 10 criterion, i had the tables linked so i could drop down the deficiencies table inside the section info table and modify it there. i added the other tables, and things just sort of blew up. i guess what i am asking is if this will work across multiple tables?
also, as i am not particularly familiar with SQL, do you think that you could define some of the syntax?
NeoPa,
i am not familiar with databases or SQL at all, so i am looking at Access like it is Excel, and while i know that is wrong, i am also thinking like i can modify it like its c/c++. i am now understanding that i am wrong. with that being said, i dont really understand what you are saying about the questions.could you slow down and teach me a little bit? im sorry for my inexperience, and i am really greatful that you are taking your time out to help me!
NeoPa 32,556
Expert Mod 16PB
I will try. A very valuable article on database design generally can be found at Normalisation and Table structures, but I'll post what I can to explain my thoughts anyway.
Assuming you currently have a structure like : Table = [tblProject] - Field Type Index
-
ProjectID Autonumber PK
-
Q0001 Boolean
-
Q0002 Boolean
-
Q0003 Boolean
-
...
You might have records like the following : - ProjectID Q0001 Q0002 Q0003 ...
-
1034 Y N Y
-
1062 N N Y
Data stored this way is hard to manipulate in the way you require. What I suggest is : Table = [tblProjectQ] - Field Type Index
-
ProjectID Number FK & 1st part of composite PK
-
QNumber Number FK & 2nd part of composite PK
-
Q Boolean
With records like the following : -
ProjectID QNumber Q
-
1034 1 Y
-
1034 2 N
-
1034 3 Y
-
1034 ...
-
1062 1 N
-
1062 2 N
-
1062 3 Y
-
1062 ...
Counting the Y or N values across a particular project would then be a simple aggregate query.
There would also be a [tblProject] and [tblQuestion] tables, but these would contain data pertaining to those items specifically, and not include the values for any questions within any project. EG. The [tblProject] would contain the name of the project and [tblQuestion] probably the security question itself.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John |
last post by:
hey all..... alright, I am frusterated to the point of throwing my
machine out
the window (this board went down, trying to find stuff on google, this
has been
a nightmare) so I hope you guys can...
|
by: krystoffff |
last post by:
Hi
I would like to paginate the results of a query on several pages. So I
use a query with a limit X offset Y to display X results on a page,
ok.
But for the first page, I need to run the...
|
by: Nick |
last post by:
Is there a (better) way to get the toal number of results from a query
but still limit them with a LIMIT clause. For example, in a Google
search result, it displays 1-100 of 10,000,000 results. Do...
|
by: Egor Shipovalov |
last post by:
I'm implementing paging through search results using cursors. Is there a
better way to know total number of rows under a cursor than running a
separate COUNT(*) query? I think PostgreSQL is bound...
|
by: Quentin Huo |
last post by:
Hi:
I want to retrieve a set of records from the query like:
"SELECT * FROM tVisitors WHERE vTime>'1/1/2004'"
And then I will put a part of records into a DataSet by:
DataSet ds = new...
|
by: Ray |
last post by:
Dear all,
I would like to ask how to know the total number of pages of the output
crystal report if I am using ReportDocument.
Thanks a lot,
Ray
|
by: patang |
last post by:
I found the following to count the total number of VISIBLE rows of datagrid
datagrid.visiblerowcount
How do we count the total number of ACTUAL (not just visible) rows of
datagrid?
Thanks...
|
by: MA |
last post by:
Hi,
How to access the total number of child nodes from a parent node. For
example, I would like to get the total number of child nodes from
<parent1and <parent2node. The SelectNodes method...
|
by: Jon Bowlas |
last post by:
Many thanks for all your reponses, much appreciated.
I'll get back to you on which is the best for me.
BTW - yes John thats exactly what I wanted.
Cheers
Jon
|
by: alwaali |
last post by:
Hi
I need help please
This is my project and i need a help to solve it with you
A page of text is to be read and analyzed to determine number of occurrences and locations of different words. The...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| |