Hello Wendy.
(Can we fix it? - Yes we can! ;-))
Wendy said:
I have looked at various examples but don't seem to be able to
get a result.
I have a table called AuthorLnkID table with two fields AuthorLnkID
and ItemLnkID. I want to tell a query to concatenate AuthorLnkID
where they have the same ItemLnkID.
The object of the exercise is to have under the title of the book the
author's names appearing in a single row in the final report.
I guess that there also is a table "Author" with AuthorName (Text)
and AuthorID (AutoNumber) fields?
You could create a query (qryAutorsForItem) that supports a parameter
(parItemID) and that lists the names of the autors for that itemID:
PARAMETERS parItemID Long;
SELECT Author.AuthorName FROM Author INNER JOIN
AuthorLnkID ON Author.AuthorID = AuthorLnkID.AuthorLnkID
WHERE (((AuthorLnkID.itemLnkID)=[parItemID]));
Then create a function in a module that returns the list (using DAO):
Public Function AuthorsForItem(ItemID As Long) As String
Dim strNames As String
Dim rst As DAO.Recordset
With CurrentDb.QueryDefs("qryAutorsForItem")
.Parameters("parItemID") = ItemID
Set rst = .OpenRecordset(dbOpenForwardOnly, , dbReadOnly)
With rst
Do Until .EOF
strNames = strNames & ", " & !AuthorName
.MoveNext
Loop
.Close
End With
.Close
End With
Set rst = Nothing
If strNames <> "" Then
AuthorsForItem = Mid$(strNames, 3)
End If
End Function
You can use this function in a query or (I'd prefer) in the report.