Link to home
Start Free TrialLog in
Avatar of thomas-sherrouse
thomas-sherrouseFlag for United States of America

asked on

Combine Unique Text Records from a Single Row into One Record Access 2007

I've got a query in Access 2007 that pulls a list of Projects that in some cases have multiple Bill Methods. I want to be able to combine the text of these Records into one record.

I've attached a Screenshot of the Access Data that I have.

User generated image
I pasted the Data in Excel and manually combined the records to show what I'm looking for.

User generated image
As you can see Project Numbers 383053 and 411062 have 2 different Bill Methods and I want to create a Function in access that combines them into one record much like the "Concatenate" Function in Excel.
Avatar of HainKurt
HainKurt
Flag of Canada image

I suggest you create a differnt table, say PaymentMethod (ProjectNumber, Billing_Method) and cleanup this table by removing the billing_method and duplicate data and insert those records into new table...

create a function like this

and call it in your query like this

select distinct project_number, companycode, getBillingMethods(project_number) BillingMethods
from myTable
Public Function getBillingMethods(project_number As Integer)
    Dim result As String
    Dim strSQL As String
    strSQL = "select * from myTable where project_number=" & project_number
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset(strSQL)
    
    While Not rs.EOF
      result = IIf(result = "", rs("Billing_Method"), result & ", " & rs("name"))
      rs.MoveNext
    Wend
    
    getBillingMethods = result
    Set rs = Nothing
End Function

Open in new window

SOLUTION
Avatar of thomas-sherrouse
thomas-sherrouse
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
put above code in Access, press Alt+F11 and copy paste code into Modules (create a new module if you dont have one)
Avatar of thomas-sherrouse

ASKER

I want to accept HainKurt's Solution as well as mine for assisting me.
I'll use both the Excel Version and Access in my Query.