Drat, Duane! I'm still having problems with it. I'm posting the SQL from
both queries and the code as it stands now and hope you can help me find my
error. Here are the references I have checked, in case that makes
difference: Visual Basic for Applications, MS Access 10.0 Object Library, MS
DAO 3.6 Object Library, OLE Automation, Microsoft Visual Basic for
Applications Extensibility 5.3.
The query to get unique values is 'qryMiniMktPlanConcatBasis'. Here's its
SQL.
SELECT DISTINCT tblFHSvcZips.FusionCustNum
FROM tblFHSvcZips;
Here's the query running the code you graciously provided.
SELECT qryMiniMktPlanConcatBasis.FusionCustNum, Concatenate("SELECT
FirstName FROM tblFHSvcZips WHERE FusionCustNum=" & [FusionCustNum]) AS Zips
FROM qryMiniMktPlanConcatBasis;
Here's the module code as it now stands. I'm getting "Run time error 3061:
Too few parameters. Expected 2." on the line indicated below. Thanks so
much for your continued help and patience, Duane. Have a great
eekend. ---Renee
Option Compare Database
Function Concatenate(pstrSQL As String, _
Optional pstrDelim As String = ", ") _
As String
'Created by Duane Hookom, 2003
'this code may be included in any application/mdb providing
' this statement is left intact
'example
'tblFamily with FamID as numeric primary key
'tblFamMem with FamID, FirstName, DOB,...
'return a comma separated list of FirstNames
'for a FamID
' John, Mary, Susan
'in a Query
'SELECT FamID,
'Concatenate("SELECT FirstName FROM tblFamMem
' WHERE FamID =" & [FamID]) as FirstNames
'FROM tblFamily
'
'======For DAO uncomment next 4 lines=======
'====== comment out ADO below =======
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(pstrSQL) ' RUN TIME ERROR 3061 HERE
'======For ADO uncomment next two lines=====
'====== comment out DAO above ======
'Dim rs As New ADODB.Recordset
'rs.Open pstrSQL, CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic
Dim strConcat As String 'build return string
With rs
If Not .EOF Then
.MoveFirst
Do While Not .EOF
strConcat = strConcat & _
.Fields(0) & pstrDelim
.MoveNext
Loop
End If
.Close
End With
Set rs = Nothing
'====== uncomment next line for DAO ========
Set db = Nothing
If Len(strConcat) > 0 Then
strConcat = Left(strConcat, _
Len(strConcat) - Len(pstrDelim))
End If
Concatenate = strConcat
End Function
Duane Hookom said:
You can do this all with one table. One possibility is to create a
totals/group by to get the "one side" unique values. Base your query with
concatenate on the totals query.
--
Duane Hookom
MS Access MVP
let way
they
looked