I copied the following into my new module (although I have no clue what it
means). When I ran Compile, I got the error message: "User defined Type
not
defined" and
the "rs As New ADODB.Recordset" in the 2nd line of the commented in
section
was highlighted (not in yellow but in blue as if I was about to copy that
section).
Incidentally I checked the appropriate Microsoft DAO x.x Object Library as
you suggested.
Any idea as to what's wrong?
Thanks again.
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)
'======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
John Spencer said:
Ok
Open Your database
Select Modules
Click on NEW
Paste in the Concatenate code from the Sample
--- Check the code
SELECT Debug: Compile from the menu
If you get errors then you will need to fix the cause. Most of the time
the
error will be due to lines wrapping.
For Duane's code, you will probably have to make sure you have the DAO
library
Menu: Tools: References
If you don't have Microsoft DAO x.x Object Library, scroll down the
list,
find it, and check it.
Close the dialog window
Duane's code has two places where you have to comment out a bit of code
and
comment in a different bit of code. He has comments on where to do that
in
the code. Comment out requires you to place an apostrophe at the start
of
the line(s) to be commented out. Comment in - remove the apostrophe.
Select Debug: Compile again and see if the code compiles.
NOW SAVE the module as MOD_Concatenate
Try your query again.
--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
Sorry, I just gave it a whirl but to ne effect. I'm going to need the
step
by
step......
:
Well, you need to do so or the concatenate function will not work.
Do you know how to do this or are you going to require step by step
directions?
--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
..
message
No I just wrote it in a regular query (as per Hookum's example).
I'm
not
very familiar with VBA...
:
Did you copy the concatenate function and paste it into a VBA
module
in
your
database and save the module with a name other than concatenate?
--
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County