Hi Douglas
Here is the code that I am using. I got it from
http://www.mvps.org/access/modules/mdl0004.htm. I would like the results
to
return something like this: Red, Blue, Green. However, it returns 8, 3,
10.
The numbers are the IDs from the bound column. (I have these items stored
in
a different table since they can be determined by a user.) I already
tried
modifying the code to use the "Column" attribute, but it would error out
or
not return anything.
I have a main form where the user enters most of the data on an issue. I
need a way for the user to select multiple types to categorize the issue.
Originally I tried using a multi-select list box, but ran into issues with
it. After spending hours on trying to fix it, I decided to simply create
a
sub form (set as a continuous form) with just the combo box to select the
issue type - this is stored in a different table than the issue. I then
embedded the subform in the main form. This allows the user to select
multiple issue types. I hope this helps explain the set up some more.
Thanks
Sidney
'************ Code Start **********
'This code was originally written by Dev Ashish
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Function fConcatChild(strChildTable As String, _
strIDName As String, _
strFldConcat As String, _
strIDType As String, _
varIDvalue As Variant) _
As String
'Returns a field from the Many table of a 1:M relationship
'in a semi-colon separated format.
'
'Usage Examples:
' ?fConcatChild("Order Details", "OrderID", "Quantity", _
"Long", 10255)
'Where Order Details = Many side table
' OrderID = Primary Key of One side table
' Quantity = Field name to concatenate
' Long = DataType of Primary Key of One Side Table
' 10255 = Value on which return concatenated Quantity
'
' Set a reference to DAO
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim varConcat As Variant
Dim strCriteria As String, strSQL As String
On Error GoTo Err_fConcatChild
varConcat = Null
Set db = CurrentDb
strSQL = "Select [" & strFldConcat & "] From [" & strChildTable & "]"
strSQL = strSQL & " Where "
Select Case strIDType
Case "String":
strSQL = strSQL & "[" & strIDName & "] = '" & varIDvalue & "'"
Case "Long", "Integer", "Double": 'AutoNumber is Type Long
strSQL = strSQL & "[" & strIDName & "] = " & varIDvalue
Case Else
GoTo Err_fConcatChild
End Select
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
'Are we sure that 'sub' records exist
With rs
If .RecordCount <> 0 Then
'start concatenating records
Do While Not rs.EOF
varConcat = varConcat & rs(strFldConcat) & ";"
.MoveNext
Loop
End If
End With
'That's it... you should have a concatenated string now
'Just Trim the trailing ;
fConcatChild = Left(varConcat, Len(varConcat) - 1)
Exit_fConcatChild:
If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If
Set db = Nothing
Exit Function
Err_fConcatChild:
Resume Exit_fConcatChild
End Function
'************ Code End **********
Douglas J. Steele said:
I'm hard-pressed to understand your setup, since combo boxes only allow
single-select. (And I never suggested not to use combo boxes: combo boxes
on
forms are fine, it's combo boxes in tables that aren't.)
Sounds to me as though the combo box is a red herring. You've got a table
that holds the data, so your code runs against that table: nothing to do
with the combo box.
So what does your code look like now?