473,396 Members | 1,996 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,396 software developers and data experts.

VBA Concatenation Assistance Request

USTRAGNU1
Team Bytes,

I have a query that is outputting a few duplicate records because of two fields, [HR Reporting].[Type of Occupational Cert] and [HR reporting].[Date Occupational Cert Issued]. I would like to output one record with the multiple certifications and dates concatenated in one field. Example of current output:

Name Certs Cert Date
Doe Jane CISSP 1/2/03 (the rest of the fields are the same)
Doe Jane SEC+ 2/3/04
Doe Jarl C++ 3/4/05
Doe John Net+ 4/5/06


Would like to display:

Name Certs And Dates
Doe Jane CISSP 1/2/03; SEC+ 2/3/04; (the rest of the fields)
Doe Jarl C++ 3/4/05
Doe John Net+ 4/5/06

Would anyone be able to give an example chunk of VBA code to make this work?

Please let me know if you have questions or require additional information and as always, thank you for your valuable time/effort.

Mike
May 3 '19 #1
4 1075
twinnyfo
3,653 Expert Mod 2GB
Probably the best way to do this is to use a User-Defined Function that concatenate those fields into one. If you do a search on this forum for “MS Access VBA Concatenate” you may be able to find several that are useful. I couldn’t find the exact specific one I was looking for, but there are several that can point you in the right direction.

Hope this hepps!
May 3 '19 #2
NeoPa
32,556 Expert Mod 16PB
Combining Rows-Opposite of Union may prove helpful.
May 4 '19 #3
ADezii
8,834 Expert 8TB
  1. Placing a Full Name in a Field called [Name] is wrong for so many reasons, but that is probably a Topic for discussion at another time.
  2. Sample Data used in Demo:
    Expand|Select|Wrap|Line Numbers
    1. ID    TName      Certs    Cert Date
    2. 1    Doe Jane    CISSP    1 /2 /2003
    3. 2    Doe Jane    SEC+     2 /3 /2004
    4. 3    Doe Jarl    C++      3 /4 /2005
    5. 4    Doe John    NET+     4 /5 /2006
    6. 5    Doe Jane    MCSE     6 /23/2007
    7. 6    Doe Jarl    PAER     12/12/2008
    8. 7    Flintstone Fred        
    9.  
  3. Create the following Query which will list all 'UNIQUE' Names sorted alphabetically and call a Function within a Calculated Field:
    Expand|Select|Wrap|Line Numbers
    1. SELECT DISTINCT tblData.TName AS Employee_Name, fConcat([TName]) AS Certification
    2. FROM tblData
    3. ORDER BY fConcat([TName]);
    4.  
  4. Function Definition:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fConcat(strName As String) As String
    2. Dim MyDB As DAO.Database
    3. Dim rstConcat As DAO.Recordset
    4. Dim strBuild As String
    5.  
    6. Set MyDB = CurrentDb
    7.  
    8. Set rstConcat = MyDB.OpenRecordset("SELECT * FROM tblDATA WHERE [TName] = '" & strName & "'", dbOpenForwardOnly)
    9.  
    10. With rstConcat
    11.   Do While Not rstConcat.EOF
    12.     strBuild = strBuild & ![Certs] & " " & ![Cert Date] & ";"
    13.       Debug.Print ![TName]
    14.         .MoveNext
    15.   Loop
    16. End With
    17.  
    18. fConcat = Left$(strBuild, Len(strBuild) - 1)
    19.  
    20. rstConcat.Close
    21. Set rstConcat = Nothing
    22. End Function
    23.  
  5. Results after Query Execution:
    Expand|Select|Wrap|Line Numbers
    1. Employee_Name    Certification
    2. Flintstone Fred     
    3. Doe Jarl    C++ 3/4/2005;PAER 12/12/2008
    4. Doe Jane    CISSP 1/2/2003;SEC+ 2/3/2004;MCSE 6/23/2007
    5. Doe John    NET+ 4/5/2006
    6.  
  6. Look at the Attachment, and should you have any questions feel free to ask.
Attached Files
File Type: zip Demo.zip (24.9 KB, 42 views)
May 5 '19 #4
Thank you all for your quick replies! I can't open the demo.zip at work, but I will give this a try, thanks!

Mike
May 6 '19 #5

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

Similar topics

1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
18
by: B Love | last post by:
I just need a small mod to my code (I think) to get the result I want. Earlier this week I had received help from FredG on concatenating a field in a form. I went on to create a field in the form...
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
4
by: Ron | last post by:
Hello, I have to concatenate some large strings which end up in a text file. I am just checking if the StringBuilder class can improve what I am currently doing - and how to implement this. ...
34
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
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: 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...
0
Oralloy
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.