Gingerale75
New member
- Local time
- Today, 13:36
- Joined
- Oct 1, 2019
- Messages
- 5
Hello All,
I'm quite new on Access, however I have basic knowledge of queries, etc. also on VBA.
I need to concatenate related fields, but not only on one level (which can be done with Allen Browne's code) but on two levels.
The source table looks like this:
Note: it's unknown that how many lines are there for the same ID & Type but in the current database it not more than 10.
Type "Use" not required, hence can be ignored, also there are "ID"s where not all four "Type" is present.
After the first conversion the table should look like:
Desired final result:
Note: the order of the "Types" changed in the final text field compared how they were in the original table.
For the first conversion step I tried to modify Allen Browne's code (sorry, cant make it as a link because I don't have enough posts yet) with adding another parameter (strWhere2) to the function at the declaration section, further down modifying the SQL string creation, and also adding the additional parameter in the Query Expression, but when I run the query it gives an error saying "Too few parameters. Expected: 1"
My modification looks like:
Of course the conversion not necessary need to be done in two steps, can be done directly.
Can anybody help me how to modify the VBA code to work, and also what expression should type into the query.
Thank you.
I'm quite new on Access, however I have basic knowledge of queries, etc. also on VBA.
I need to concatenate related fields, but not only on one level (which can be done with Allen Browne's code) but on two levels.
The source table looks like this:
Code:
ID Type Line Text
100 Action 1 ccc
100 Action 2 CCC
100 Probl 1 aaa
100 Probl 2 AAA
100 Cause 1 bbb
100 Cause 2 BBB
100 Use 1 12
110 Action 1 zzz
110 Probl 1 xxx
110 Probl 2 XXX
110 Cause 1 yyy
110 Use 1 3
120 Action 1 kkk
120 Action 2 KKK
Type "Use" not required, hence can be ignored, also there are "ID"s where not all four "Type" is present.
After the first conversion the table should look like:
Code:
ID Type Text
100 Action ccc, CCC
100 Probl aaa, AAA
100 Cause bbb, BBB
110 Action zzz
110 Probl xxx, XXX
110 Cause yyy
120 Action kkk, KKK
Code:
ID Text
100 Probl: aaa, AAA; Cause: bbb, BBB; Action: ccc, CCC
110 Probl: xxx, XXX; Cause: yyy; Action: zzz
120 Action: kkk, KKK
For the first conversion step I tried to modify Allen Browne's code (sorry, cant make it as a link because I don't have enough posts yet) with adding another parameter (strWhere2) to the function at the declaration section, further down modifying the SQL string creation, and also adding the additional parameter in the Query Expression, but when I run the query it gives an error saying "Too few parameters. Expected: 1"
My modification looks like:
Code:
Public Function ConcatRelatedUSA(strField As String, _
strTable As String, _
Optional strWhere1 As String, _
[U][B]Optional strWhere2 As String, _[/B][/U]
Optional strOrderBy As String, _
Optional strSeparator = " ") As Variant
and further down.....
If strWhere1 <> vbNullString And strWhere2 <> vbNullString Then
strSql = strSql & " WHERE ((" & strWhere1 & ") AND (" & strWhere2 & "))"
End If
but got the error on this line:
Set rs = DBEngine(0)(0).OpenRecordset(strSql, dbOpenDynaset)
Can anybody help me how to modify the VBA code to work, and also what expression should type into the query.
Thank you.