Need answer to: Is there a reference table that associates names with the Field1 IDs? Must the import data serve as the reference that will provide the ID to associate with each name? Could names be duplicated in Field2? Like:
Field 1 (pk) |
Field 2 |
Field 3 |
1 |
Bob |
|
2 |
Frank |
Bob, Joe |
3 |
Joe |
Bob |
4 |
Sara |
Bob, Joe, Frank |
5 |
Bob |
Sara, Joan |
This function will convert names to IDs using original sample data. Assumes every name in Field3 has a corresponding ID in Field1 and no duplicates in Field2:
Code:
Function ConvertNames(strNames As String) As Variant
Dim arrNames As Variant
Dim strIDs As String
Dim i As Integer
If Len(strNames) = 0 Then
ConvertNames = Null
Else
arrNames = Split(Replace(strNames, " ", ""), ",")
For i = 0 To UBound(arrNames)
strIDs = strIDs & DLookup("Field1", "Table1", "Field2='" & arrNames(i) & "'") & ", "
Next
ConvertNames = Left(strIDs, Len(strIDs) - 2)
End If
End Function
Place the function in a general module and then call from query, textbox, or VBA.
SELECT Field1, Field2, Field3, ConvertNames(Nz([Field3],"")) AS F3Conv FROM Table1;
Ordering the IDs sequentially within the string is a whole other issue I don't want to tackle. Review http://social.msdn.microsoft.com/For...b-d860773281f7