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

Newbie trying to Concatenate

4
Hello,
Hopefully this is a simple problem that someone can help me with easily. I have one table with two fields. The first field contains a subnet_org and the second contains a subnet. The first column has many duplicates because some "orgs" have numerous subnets....which are all listed in the second field in inidividual rows.
Org Subnets
Rogers 10.10.1.0/81
Rogers 10.10.1.0/82
Shaw 10.10.1.0/24
Shaw 10.10.1.0/25
Shaw 10.10.1.0/38
Telus 10.10.1.0/39
Telus 10.10.1.0/40
Telus 10.10.1.0/41
Telus 10.10.1.0/42
Telus 10.10.1.0/43

I need to run a query whose output concatenates the subnet for each org....so the output looks thusly:
Telus 10.10.1.0/39, 10.10.1.0/40, 0.10.1.0/41....etc
with one row for each org.

Thanks in advance for any help anyone can offer.
Cheers!
Feb 25 '08 #1
10 1937
ADezii
8,834 Expert 8TB
Hello,
Hopefully this is a simple problem that someone can help me with easily. I have one table with two fields. The first field contains a subnet_org and the second contains a subnet. The first column has many duplicates because some "orgs" have numerous subnets....which are all listed in the second field in inidividual rows.
Org Subnets
Rogers 10.10.1.0/81
Rogers 10.10.1.0/82
Shaw 10.10.1.0/24
Shaw 10.10.1.0/25
Shaw 10.10.1.0/38
Telus 10.10.1.0/39
Telus 10.10.1.0/40
Telus 10.10.1.0/41
Telus 10.10.1.0/42
Telus 10.10.1.0/43

I need to run a query whose output concatenates the subnet for each org....so the output looks thusly:
Telus 10.10.1.0/39, 10.10.1.0/40, 0.10.1.0/41....etc
with one row for each org.

Thanks in advance for any help anyone can offer.
Cheers!
I'll have an answer for you shortly, last one before I go tp bed.
Feb 25 '08 #2
ADezii
8,834 Expert 8TB
Hello,
Hopefully this is a simple problem that someone can help me with easily. I have one table with two fields. The first field contains a subnet_org and the second contains a subnet. The first column has many duplicates because some "orgs" have numerous subnets....which are all listed in the second field in inidividual rows.
Org Subnets
Rogers 10.10.1.0/81
Rogers 10.10.1.0/82
Shaw 10.10.1.0/24
Shaw 10.10.1.0/25
Shaw 10.10.1.0/38
Telus 10.10.1.0/39
Telus 10.10.1.0/40
Telus 10.10.1.0/41
Telus 10.10.1.0/42
Telus 10.10.1.0/43

I need to run a query whose output concatenates the subnet for each org....so the output looks thusly:
Telus 10.10.1.0/39, 10.10.1.0/40, 0.10.1.0/41....etc
with one row for each org.

Thanks in advance for any help anyone can offer.
Cheers!
OK, I'm back, but first three simple Assumptions:
  1. Table Name is tblTest
  2. Field 1 Name is [Org]
  3. Field 2 Name is [Subnet]
  1. Function that does all the work. It is called by the Calculated Field 'All_Subnets' in the Query for each unique [Org]:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fConcatenateSubnets(strOrg As String) As String
    2. Dim MyDB As DAO.database, MyRS As DAO.Recordset
    3. Dim strBuildString As String
    4.  
    5. Set MyDB = CurrentDb
    6. Set MyRS = MyDB.OpenRecordset("tblTest", dbOpenForwardOnly)
    7.  
    8. strBuildString = ""     'initialize
    9.  
    10. Do While Not MyRS.EOF
    11.   If MyRS![Org] = strOrg Then
    12.     strBuildString = strBuildString & MyRS![Subnet] & ", "
    13.   End If
    14.     MyRS.MoveNext
    15. Loop
    16.  
    17. 'Strip out the last Space and , ==> namely "' "
    18. fConcatenateSubnets = Left$(strBuildString, Len(strBuildString) - 2)
    19.  
    20. MyRS.Close:Set MyRS = Nothing
    21. End Function
  2. Query SQL Statement:
    Expand|Select|Wrap|Line Numbers
    1. SELECT DISTINCT tblTest.Org, fConcatenateSubnets([Org]) AS All_Subnets
    2. FROM tblTest
    3. ORDER BY tblTest.Org;
  3. Output based on your data:
    Expand|Select|Wrap|Line Numbers
    1. Org           All_Subnets
    2. Rogers       10.10.1.0/81, 10.10.1.0/82
    3. Shaw       10.10.1.0/24, 10.10.1.0/25, 10.10.1.0/38
    4. Telus       10.10.1.0/39, 10.10.1.0/40, 10.10.1.0/41, 10.10.1.0/42, 10.10.1.0/43
  4. Any questions, please feel free to ask.
Feb 25 '08 #3
bingus
4
ADezii,

Thank you so much for your quick response. I'm not only new to VBA but also Access. I'm sure your code will work marvelously once I figure out the issues I'm having with Access.

I keep getting a "function is undefined" message when I try and run the query. I know it's something I'm doing, or not doing, because I can run sample queries that call functions....like Northwind type stuff........but even if I recreate the exact same table, function then query as the Northwind sample...I still get this error. But when I call the Northwind function in my own query against my own table....it works fine....go figure!

Anyway, thanks again.....I'll keep plugging away!!


OK, I'm back, but first three simple Assumptions:
  1. Table Name is tblTest
  2. Field 1 Name is [Org]
  3. Field 2 Name is [Subnet]
  1. Function that does all the work. It is called by the Calculated Field 'All_Subnets' in the Query for each unique [Org]:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fConcatenateSubnets(strOrg As String) As String
    2. Dim MyDB As DAO.database, MyRS As DAO.Recordset
    3. Dim strBuildString As String
    4.  
    5. Set MyDB = CurrentDb
    6. Set MyRS = MyDB.OpenRecordset("tblTest", dbOpenForwardOnly)
    7.  
    8. strBuildString = ""     'initialize
    9.  
    10. Do While Not MyRS.EOF
    11.   If MyRS![Org] = strOrg Then
    12.     strBuildString = strBuildString & MyRS![Subnet] & ", "
    13.   End If
    14.     MyRS.MoveNext
    15. Loop
    16.  
    17. 'Strip out the last Space and , ==> namely "' "
    18. fConcatenateSubnets = Left$(strBuildString, Len(strBuildString) - 2)
    19.  
    20. MyRS.Close:Set MyRS = Nothing
    21. End Function
  2. Query SQL Statement:
    Expand|Select|Wrap|Line Numbers
    1. SELECT DISTINCT tblTest.Org, fConcatenateSubnets([Org]) AS All_Subnets
    2. FROM tblTest
    3. ORDER BY tblTest.Org;
  3. Output based on your data:
    Expand|Select|Wrap|Line Numbers
    1. Org           All_Subnets
    2. Rogers       10.10.1.0/81, 10.10.1.0/82
    3. Shaw       10.10.1.0/24, 10.10.1.0/25, 10.10.1.0/38
    4. Telus       10.10.1.0/39, 10.10.1.0/40, 10.10.1.0/41, 10.10.1.0/42, 10.10.1.0/43
  4. Any questions, please feel free to ask.
Feb 26 '08 #4
ADezii
8,834 Expert 8TB
ADezii,

Thank you so much for your quick response. I'm not only new to VBA but also Access. I'm sure your code will work marvelously once I figure out the issues I'm having with Access.

I keep getting a "function is undefined" message when I try and run the query. I know it's something I'm doing, or not doing, because I can run sample queries that call functions....like Northwind type stuff........but even if I recreate the exact same table, function then query as the Northwind sample...I still get this error. But when I call the Northwind function in my own query against my own table....it works fine....go figure!

Anyway, thanks again.....I'll keep plugging away!!
The Function must be declared as 'Public' in a 'Standard' Code Module, That is probably why you are getting the Error:
Expand|Select|Wrap|Line Numbers
  1. Public Function fConcatenateSubnets(strOrg As String) As String
Feb 26 '08 #5
NeoPa
32,556 Expert Mod 16PB
Producing a List from Multiple Records may help with this (as an alternative).
Feb 26 '08 #6
bingus
4
Thanks again ADezii and NeoPa!!

I've been trying to implement your code at my office and have not been successful. Tonight is the first night I've tried this at home and it works!! I don't know what is different .....but it doesn't matter because I know I can get the job done.

I really appreciate all your help.

Thanks again.......;-)
Feb 27 '08 #7
ADezii
8,834 Expert 8TB
Thanks again ADezii and NeoPa!!

I've been trying to implement your code at my office and have not been successful. Tonight is the first night I've tried this at home and it works!! I don't know what is different .....but it doesn't matter because I know I can get the job done.

I really appreciate all your help.

Thanks again.......;-)
That is why we are all here, it definately is not the salary! (LOL).
Feb 27 '08 #8
NeoPa
32,556 Expert Mod 16PB
Well done :)
Are the versions of Access both the same (at home and at work)?
Feb 27 '08 #9
bingus
4
Almost out of the woods!!
How can I change the format of the All_Subnets field to "memo" .....if that is what is required.

My issue, now, is that some of my "Orgs" have over 300 subnets and I've found some of the "All_Subnets" fields have truncated the data and contain the maximum 255 characters of a text field only. Fortunately of the 200 odd "Orgs" I have only about 10% of them present me with this issue.

Any ideas on this one?
Feb 28 '08 #10
NeoPa
32,556 Expert Mod 16PB
I'm not sure there is a way. I tried to force something similar to this using the PARAMETERS clause earlier, but I found it wouldn't work as I intended. I doubt it'll be much use to you either. Sorry :(
Feb 28 '08 #11

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

Similar topics

0
by: Nick Heppleston | last post by:
I have a concatenation problem and I was wondering if somebody might be able to offer some help :-) I have the following table structure holding product long descriptions: Part...
30
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
14
by: metamorphiq | last post by:
Hello, I'm a Java programmer, so I'm probably asking a very simple question here, but I have trouble solving it :) I'd like to know how you concatenate multiple (4, in my case) char* in C++,...
2
by: exapplerep | last post by:
I've seen how to use VBA code to concatenate two fields into a third by using an expression in the "After Update" property in fields 1 & 2. field3 = field1 + field2 The above code would go...
4
by: Dan | last post by:
Hi all, I am creating a search table where the keywords field is made up of several text fields and this is causing me some problems. I can concatentate the text ok but i can't seem to concatenate...
12
by: parth | last post by:
Hi I want to achieve the following transformation of data using a stored procedure. Source col1 col2(varchar) -------------------------
8
by: Goran | last post by:
Hi all, I want to store data with << like this way: myClass_t aObject; string aString("foo"); // no output, just edit and store the string aObject << aString;
13
by: sinbad | last post by:
hi, how to concatenate a "hash defined" constant value to another "hash defined" constant string. For example #define ABC 100 #define MYSTR "The value of ABC is" Now i need a string that...
10
by: Aaron Hoffman | last post by:
Hello, I'm hoping someone might be able to offer some guidance to my problem. I have one query in MS Access which consists of 2 tables joined by a SEQUENCE_ID. By joining the two tables I am...
8
by: jch | last post by:
Sorry for the newbie question but I'm trying to learn Visual Studio. I've got VS Express 2008 and I'm using visual basic. I'm trying to learn how to deploy a program so I've written a very basic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.