S
Sheldon Slade
I need a snippet of code to convert a list of names (from
a table or SELECT statement) to a single comma-separated
string (for display in a text box). Here's what I have:
Public Function StringFromList(TableName, FieldName As
String) As String
Dim OngoingString As String, GetNames As Object
Set GetNames = CurrentDb.OpenRecordset(TableName)
GetNames.MoveFirst
OngoingString = GetNames(FieldName)
For xMarker = 1 To GetNames.RecordCount - 1
GetNames.MoveNext
If GetNames.EOF = True Then GoTo GotEmAll
OngoingString = OngoingString & ", " & GetNames
(FieldName)
Next
GotEmAll:
GetNames.Close
StringFromList = OngoingString
End Function
When I use a table name as the argument, it works as it
should. But if I use a query or SQL statement, it
invariably returns only one record's information.
Queries in the rest of the DB seem to be fine, but
whenever I create a recordset from one in VB I get a
RecordCount of 1. Anyone see my mistake?
TIA
Sheldon
a table or SELECT statement) to a single comma-separated
string (for display in a text box). Here's what I have:
Public Function StringFromList(TableName, FieldName As
String) As String
Dim OngoingString As String, GetNames As Object
Set GetNames = CurrentDb.OpenRecordset(TableName)
GetNames.MoveFirst
OngoingString = GetNames(FieldName)
For xMarker = 1 To GetNames.RecordCount - 1
GetNames.MoveNext
If GetNames.EOF = True Then GoTo GotEmAll
OngoingString = OngoingString & ", " & GetNames
(FieldName)
Next
GotEmAll:
GetNames.Close
StringFromList = OngoingString
End Function
When I use a table name as the argument, it works as it
should. But if I use a query or SQL statement, it
invariably returns only one record's information.
Queries in the rest of the DB seem to be fine, but
whenever I create a recordset from one in VB I get a
RecordCount of 1. Anyone see my mistake?
TIA
Sheldon