I have a table with 7 columns and 50 rows.
The first column is a unique ID#, the other 6 columns are for names. (Name1, Name2, ......Name6).
I need to create a 2 column query to extract the six names that belong to each unique ID. It doesn't matter that the ID will be repeated multiple times in the same column, I'll deal with that later. I just need to have the query results with an ID# column and a single Name column.
Any help would be appreciated.
4 1801
What sort of setup are we talking about? VB? What version? By "table" are you referring to a database table? What sort of database?
Yes, it's an Access 2002 database table. I'd like it to be just a standard select query if possible, that I can use in creating a report. (It will actually be used as part of a cascading set of queries).
Yes, it's an Access 2002 database table. I'd like it to be just a standard select query if possible, that I can use in creating a report. (It will actually be used as part of a cascading set of queries).
In that case I'm going to move this over the the Access forum, as you'll find much more Access expertise there.
Yes, it's an Access 2002 database table. I'd like it to be just a standard select query if possible, that I can use in creating a report. (It will actually be used as part of a cascading set of queries).
Now this is by no means the only way to do this, neither is it as efficient as it could be. I have done it for you for 'clarity' rather than technical excellence... it merely gives you a very simple insight into calling a function, looping using an array and returning the result of that function to the SELECT query that called it. Assumptions
Going by your example lets say you have a table called tblRush and fields names called ....Name1,Name2 ,Name3,Name4,Na me5,Name6
(This function is not concerned with your ID column as that is merely your row reference and not vital to this function) Paste this fully commented function below into a module and save it -
-
'This function takes the names of the six fields passed in
-
'and returns a concatenated string of values as the result
-
'Typical SQL syntax to use this example for a table called tblRush will be:
- ' SELECT tblRush.ID, fn_RushNames([Name1],[Name2],[Name3],[Name4],[Name5],[Name6]) AS Available_Names
- ' FROM tblRush;
-
-
' You obviously need to amend the fieldnames and table name to suit you
-
-
'define an zero based array consisting of the six variant variables passed in
-
Dim RushArray(5)
-
RushArray(0) = n1
-
RushArray(1) = n2
-
RushArray(2) = n3
-
RushArray(3) = n4
-
RushArray(4) = n5
-
RushArray(5) = n6
-
'loop through the elements of the array until the upper bound limit
-
'concatenatating each value and assigning a trailing comma
-
'skip over where a column might be null by converting to zero
-
'and testing for the zero value
-
For i = 0 To UBound(RushArray)
-
If Nz(RushArray(i), 0) = 0 Then
-
fn_RushNames = fn_RushNames
-
Else
-
fn_RushNames = fn_RushNames & RushArray(i) & ","
-
End If
-
Next i
-
'By now we have a string of values if at least one cell has a value
-
'separated by a comma so we strip off the trailing comma and return the result
-
'In the event of no values at all in any of the cells we test for a zero length
-
'string and return a value stating there are no values in ANY of the fields for
-
'that particular row
-
If fn_RushNames = "" Then
-
fn_RushNames = "No values available for any or the six columns"
-
Else
-
fn_RushNames = Left(fn_RushNames, Len(fn_RushNames) - 1)
-
End If
-
End Function
-
Like I mentioned it is not the only way to do it. You can concatenate directly in the grid without using this function at all and test for nulls etc but I'll leave anyone else to give you their examples.
Regards
Jim
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Matthew Braumiller |
last post by:
On Thu, 2 Oct 2003, "Gary Floam" <floam@comcast.net> wrote:
>Sure you can do that. The easies way is to create a table of the last names
>selected, and join that table into the query definition.
>
>If you write your own SQL, you can create a string something like
> where LastName in ("Smith", "Jones", "Brown")
>
>Good luck
>
|
by: John young |
last post by:
I have been looking for an answer to a problem and have found this
group and hope you can assist .
I have been re doing a data base I have made for a car club I am with
and have been trying to make a query that selects from a table as
desribed below ..
I have a table (Volunteer) that has a member field (memnumber)
and a number of fields that are headed in various categories and are
yes/no formated
|
by: Martin Lacoste |
last post by:
(Access 2000)
Two issues:
Within a query, I need to return a field name as data (see eg. below).
I need to search within 80 fields (same criteria) - is there a way to
avoid 80 separate expressions (the 80 field names are stored in a
table - can I get the query to look each of these up?)?
Here's an example:
|
by: dskillingstad |
last post by:
I'd appreciate any help I can get. I'm not sure what I'm doing wrong,
but....
I've searched these groups for some solutions but no luck.
I have an unbound form (frmSearch), with several unbound text boxes on
it and a command button bound to a macro which fires off a parameter
query based on the criteria/string that the user types into the text
boxes on frmSearch. My goal is to create a search form where the user
can search by any of...
|
by: Serious_Practitioner |
last post by:
Good day, and thank you in advance for any assistance you can provide.
I have a table in an Access 2000 .mdb file, and I've run into something odd
and insolvable, at least for me. The database is for membership information.
This particular table, called tblMembershipInfo, has fields/columns as
follows -
fldMemNum - Member Number
fldActionDate - The date when the entry was made in that row - Data type is
Date/Time, no format specified
| |
by: Jimbo |
last post by:
Hello,
I have a user request to build a form in an Access database where the user
can check off specific fields to pull in a query. For example, let's say I
have 10 fields in a table. The user wants to be able to check off anywhere
between 1 and all 10 fields in a form and have it return a select query with
just the fields that were checked off. There are multiple users, so not all
users will be checking off the same fields. Some...
|
by: Allen Anderson |
last post by:
Hi,
I'm trying to design contact (names and addresses) tables in an Access
database. Some of the contacts represent vendors, some are board members of
the organization, some are donors, some are neighbors of the organization,
some are politicians, etc. Rather than create separate tables for each type
of contact, I thought it would be better to have:
one table with names/addresses
one table with kinds of lists (vendors, board...
|
by: Robert |
last post by:
I am an attorney in a non-profit organization and a self-taught programmer.
I'm trying to create a client db that will allow me to search for potential
conflicts of interest based either on Social Security # or on Last Name.
I've created two different tables with the following fields in each table:
ClientInfo
Client# (primary key)
First Name
Middle Name
Last Name
|
by: JJM0926 |
last post by:
I'm trying to create a running totals query in access 97. I have
followed the directions on how to do it from Microsofts website
article id 138911. I took their code they had and replaced it with my
fields. When I try to run it I get #errors in my RunTot column. I'm
kinda new to this. Not sure if maybe I mistyped something wrong or is
there a better way to do this? I have pasted the code. Any help would
be greatly appreciated....
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |