Hi everyone, I have spent a few hours searching and cannot find an example that is similar enough for me to work with.
Is it possible to combine multiple rows by creating new columns? Searching the forum makes me believe it will take some VBA code.
What I have:
Number | person | email | phone | fax | Y/N | time
1 | bob | b.com | 123 | 123 | Y | 5:00
8 | bob | b.com | 888 | 888 | N |
4 | bob | b.com | 123 | 123 | Y | 5:00
1 | sue | s.com | 456 | 456 | N |
5 | sue | s.com | 456 | 456 | N |
What I'm looking for:
person | email | phone | fax | 1 | in_1 | 4 | in_4 | 5 | in_5 | 8 | in_8
bob | b.com | 888 | 888 | 5:00| Y | Y | 5:00 |NULL | N | N | Y
sue | s.com | 456 | 456 | N | Y |NULL | N | N | Y |NULL | N
It will take each different value in the number column and create a new column titles with the value.
It will update the phone and fax with the most recent value (The highest number in the number column will always be the most recent value.)
If the value is Yes, it will put the time instead of yes. If the value is no, it will put no.
If the person does not have a number that someone else has it will put no in the in_# column, else it will put yes.
This may take several queries to break the data apart better.
Any help would be greatly appreciated, I am new to access and have only created basic queries.
16 3068
You would actually want to do this in a related table as records and not as new fields. See Database Normalization and Table Structures. By doing it this way, you can add unlimited number of values without having to code anything or change the design of anything.
What you are asking for could get pretty complicated and would most likely result in some VBA. The reason it could get complicated is that it isn't a standard practice in a Database and is akin to de-normalization. There is a slim chance what you are looking for could be accomplished by a Crosstab Query, but I wouldn't get your hopes up.
So, before heading down a development path, it would probably be best to ask what you are attempting to accomplish with this? There may be a simpler solution; a solution more inline with the tools available in Access.
I will look into what both of you have suggested, thank you.
For now there doesn't seem to be an easy way of doing this.
I was able to figure out how to replace the Yes with the time so instead of having a Yes/No column and a time column the new column is No/Time where if it is a yes it will show the time instead of the work yes.
This is certainly doable. And we can help you do it. But before we can, you have to answer jforbe's question.
Thanks Rabbit, I read his question but completely skipped it in my response.
I have multiple rows per user, along with a number for each user. There can be multiple numbers per user. I am trying to combine multiple rows for each user into one row per user but create a column titled with that number and place a value whether or not the user has that number. Let me know if that makes sense, it sounds confusing trying to type it out.
That's what you want to do. The question is why. We understand what it is you want to accomplish, but if you tell us the why, you may find out that you don't need to do it that way at all.
I need to be able to view a list of all the people in order to figure out who is a Yes or No for each Number. It is just for reporting purposes so there is one list of all of the users and what numbers they are a yes or no for. (Hopefully this counts as a why.)
The next question is, does it have to be in that format? There's multiple ways to lay out that information and although I see the appeal of that layout, that's one of the more complicated methods to accomplish.
Yes it has to be in that format unfortunately.
I was able to create a crosstab query that does almost everything that I need.
person | email _| phone | fax | total __| total_Y __| 1 ___| 4 __| 5 | 8
bob ___| b.com | 888 __| 888 | 3 ____| ??_2_?? | 5:00 | 5:00 | 0 | N
sue ___| s.com | 456 __| 456 | 2 ____| ??_0_?? | N ___| 0 __| N | 0
A 0 means that the person does not have that number.
A N means they have that number but the value should be No
A time means they have the number and the value is a yes but I needed the time instead of yes.
I also have a total column that calculates the total numbers that each person has.
However, I need a column that calculates the total times each person has. I think this could use the Len() function to calculate the total of values that are longer than 1 character but I am having issues creating this column. And ideas?
I would create a separate Query to calculate the totals, then create a third query to join the Crosstab Query you have with the New Totals Query on the Person. It will be easier to create and easier to maintain.
If you want to keep your query count down, create a Query based off the Crosstab Query, and add a column to select a Sum() from the base Table, kinda like: - SELECT
-
Crosstab.*
-
, (SELECT Sum(Time) FROM BaseTable WHERE BaseTable.Person=Crosstab.Person) AS TotalTime
-
FROM Crosstab
In addition to jforbes suggestions, you can use the IIf() function to change your values that are displayed, you can also combine it with a sum to get your total Y count.
Rabbit, can you elaborate a little more on your idea. I have looked at jforbes response but am trying to get everything into one query if possible. I have used IIf, Nz and Len before and understand how they work, but not exactly sure what you are suggesting.
I can get the Total values in both the Total and Total_Y columns and I can also get the Total_Y values in both columns but I cannot get each in their own column at this point. If I use a WHERE Len(...)>2 I can get the desired results for the Total_Y column but the results also appear in the Total column since it filters those out completely. Can I use the WHERE filter only for one column or SELECT value?
I have looked at jforbes response but am trying to get everything into one query if possible.
This (probably) won't be possible with everything you're trying to do.
I have used IIf, Nz and Len before and understand how they work, but not exactly sure what you are suggesting.
You said you want to display different values depending on the value of the field. You can do this using the IIf function. - IIf(field1 = 'some value', 'other value', field1)
Basically, what this does is, if field1 is equal to some value, return other value instead. Otherwise, for all other values of field1, return the original value.
Can I use the WHERE filter only for one column or SELECT value?
Nope.
Okay that is helping. I might have phrased one of my questions wrong.
If I have
# | 1 | 2 | 3 | 4 | 5
A | 0 | Y | N | Y | 0
B | N | N | 0 | 0 | 0
Can I create a both a column to sum the total Y and N in a row, and another column to sum just the Y in a row with only one query? Or will I have to go the route suggested above with multiple queries?
You can, but it's convoluted. It's easier to go with a separate query as jforbes suggested. And then combine them into one result set.
Okay thank you, that is the approach I am working on now.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jackiefm |
last post by:
I realize the thread I am responding to was posted in January but I am basically having the same issue. I am not familiar with VBA but use Access daily. I have written simple scripts but nothing to...
|
by: madhanmss |
last post by:
Hi,
How to freeze multiple rows and columns in a datagrid. It should be like an excel sheet, if you scroll horizontally, columns should be freezed and if u scroll vertically, rows should be...
|
by: Jeremy Goodman |
last post by:
Access 2007; Merging records containing multivalue drop down lists.
I have a database showing legislation information divided by State/territory. The database needs to be able to show the info...
|
by: samuel ray |
last post by:
Hi,
I'm using AIX(ksh shell).
> cat temp.txt
"a","b",0
"c",bc",0
"a1","b1",0
"cc","cb",1
|
by: jamespfisher |
last post by:
Hey all
I'm writing a large extract report on clients of a pharmacy and the drugs they are prescribed (maximum of 6 drugs in total).
Data structure of the drugs table looks like this:
...
|
by: almaroc |
last post by:
i am using access 2007 and i am trying to combine multiple rows into one. i am using the code from this site but i continue to get this error:
Compile error in query expression....
|
by: wyosorensen |
last post by:
Hi,
I work for an insurance company and what I'm doing is creating a database for writing policies where I can have one policy that covers multiple buildings. I have a form that they can fill out...
|
by: PreethiGowri |
last post by:
I have a table something like
name id date login logout
arjun 1 2012-11-28 9-30 7-30
arjun 1 2012-11-29 9-30 8-00
arjun 1 2012-11-30 9-40 8-00
i want to...
|
by: Jrod2541 |
last post by:
So I have a table named Table1. Inside Table1 are the fields: SKU, VendrItem, Qty and EachCost.
SKU VendrItem Qty EachCost
123 ABC 2 $2
123 ABC 5 $2 ...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |