473,624 Members | 2,288 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query values without specifying field names?

Odd problem. I have a table in the following format:

DocID Question1 Question2 Question3
------------------------------------------------
298 1, 2, 3 or 0

Each Question field will have 1,2,3 or 0 if not completed. The number
of Question fields will vary.

I need to count all the questions, then figure out how many have 0
answers. Is there any way to query values dynamically when the field
names change. I'm trying to avoid writing multiple queries, each with
hundreds of field names.

Thanks for any help provided...I'm probably out in left field.

Kat

Nov 13 '05 #1
3 1721
I'm not sure if I understand your question or not.
Do you have 1 table, or many tables?
If there's just the one table, you should know how many fields it
has....

Nov 13 '05 #2
Kathy Burke,
This is a lot easier if you have something like:

Doc_tbl
---->Question_tbl

so that question table is the many side of a one-to-many relationship with
the Doc_tbl. I'd be tempted to quietly write some code that iterated
through the fields looking for zeros and building a temporary table listing
the questions with zeros for a given doc_tbl record.

--
Alan Webb
kn*******@SPAMh otmail.com
"It's not IT, it's IS"

<ka**********@c omcast.net> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
Odd problem. I have a table in the following format:

DocID Question1 Question2 Question3
------------------------------------------------
298 1, 2, 3 or 0

Each Question field will have 1,2,3 or 0 if not completed. The number
of Question fields will vary.

I need to count all the questions, then figure out how many have 0
answers. Is there any way to query values dynamically when the field
names change. I'm trying to avoid writing multiple queries, each with
hundreds of field names.

Thanks for any help provided...I'm probably out in left field.

Kat

Nov 13 '05 #3
Fasten your seat belts, this is gonna get ugly.

As I see it, the only way to get your data to be queryable is to
normalize your table structure. What you really need is your data to
be in a format like this:

DocID, QuestionID, Answer

Without writing zillions of individual queries, this is a pain. So
write some code to do it for you. (If you can't understand code, this
*might* be a problem, but it's either use code or do it manually...)
So, here's what I came up with:

'---BEGIN CODE-----

Option Compare Database
Option Explicit

Public Sub NormalizeTable( ByVal strSrcTable As String)
'--Sample Call: NormalizeTable "MyTable"
'--ASSUMES you have a table called "tblSurvey" , with 3 fields:
'--DocID - Long Integer, primary key(1)
'--QuestionNo - Long Integer, primary key (2)
'--Answer - Long Integer, the number you were storing in the Q(n)
field.

Dim dbs As DAO.Database
Dim tdfSrc As DAO.TableDef
Dim intCounter As Integer
Dim strSQL As String
Set dbs = DBEngine(0)(0)

'--point at the table containing your data
Set tdfSrc = dbs.TableDefs(s trSrcTable)

'--loop through the fields in the table, appending the SurveyID
(docNo), QuestionID, and Answer to the Survey table

For intCounter = 1 To tdfSrc.Fields.C ount - 1
'Create the SQL statement
strSQL = "INSERT INTO tblSurvey (DocID, Answer, QuestionNo)
SELECT [" & tdfSrc.Name & "].[" & tdfSrc.Fields(0 ).Name & "], [" &
tdfSrc.Fields(i ntCounter).Name & "], " & intCounter & " AS Expr1 FROM
tblQs;"
'Execute the SQL statement
dbs.Execute strSQL, dbFailOnError
Next intCounter

Set tdfSrc = Nothing
Set dbs = Nothing

End Sub

'---CODE END----

You have to create the tblSurvey table for this to work. Sorry, didn't
feel like messing with making it properly generic - just wanted to get
it working first!

HTH,
Pieter

Nov 13 '05 #4

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

Similar topics

22
31184
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for June, and will return all records in that month.
8
3473
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 , etc. I want to go to the first row, do a WHERE statement, return the
4
4572
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
9
3625
by: Sinner | last post by:
Hi, I have a field name 'USER' in tableMAIN. How do I replace the user names with corresponding user names. I can do that in xl using vlookup but now I'm trying to find a way to do that in access. For a user mismatch, it should give NA Thx.
0
8240
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8625
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7168
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.