Jamal,
Here is a function that will do what you need.
There is a problem, though.
When I tried to run this function using data from Table14 - instead of the visible values for Field2, Field3 & Field4 - I was getting only integer values [like 1, 2, 3, 4 . . .].
If you want to see the problem - try this:
Open Table14.
Press Ctrl + A - and then Ctrl + C [to copy all the data].
Open Table18
Click to the left of the Last [New - *] row of the Table - so that the row is selected/highlighted.
Click Ctrl + V to paste the data from Table14.
You should see what I am trying to describe.
??
I think this is because the values in Table14 are lookup values???
So when I run the function I am getting the lookup Value - rather than the text.
Honestly, I don't know because I have never used lookup fields in tables.
I am busy with work so I don't have the time to figure out how to overcome that
[

]
. . . so I created a Table named AA_Test - which has the same data as your Table14 [AA_Test has fields named One, Two, Three, Four].
I ran the function using data from AA_Test.
In the function, I wrote the summarized data to another empty table I created named AA_Test_Write [which has fields named One, Two, Three, Four].
Code:
Function Get_DB_Values()
'Get values from a table using a query in VBA.
'Process values row by row.
'Insert processed row into another Table.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strField1, strField2, strField3, strField4 As String
Dim strNewField1, strNewField2, strNewField3, strNewField4 As String
Dim strSQL As String
Dim intRecordCount As Integer
On Error GoTo Error_Handle
Set db = CurrentDb
strSQL = "Select * From [AA_Test] ORDER BY [One], [Two], [Three], [Four]"
intRecordCount = 1
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
With rs
'This Do While loop goes through all the records in strSQL.
Do While Not rs.EOF
If intRecordCount = 1 Then
strField1 = rs![One]
strField2 = rs![Two]
strField3 = rs![Three]
strField4 = rs![Four]
intRecordCount = intRecordCount + 1
Else 'Not first record.
strNewField1 = rs![One]
If strNewField1 = strField1 Then 'Same Field1 - concatenate values.
strNewField2 = rs![Two]
strNewField3 = rs![Three]
strNewField4 = rs![Four]
strField2 = strField2 & ", " & strNewField2
strField3 = strField3 & ", " & strNewField3
strField4 = strField4 & ", " & strNewField4
Else 'Field1 changed - Write the record to other table.
'Create Insert SQL.
strSQL = "INSERT INTO AA_Test_Write (One, Two, Three, Four) "
strSQL = strSQL & "VALUES (" & "'" & strField1 & "'" & ", " & "'" & strField2 & "'" & ", " & "'" & strField3 & "'" & ", " & "'" & strField4 & "'" & "); "
'Execute Insert SQL
DoCmd.RunSQL strSQL
'Populate current row values into variables.
strField1 = rs![One]
strField2 = rs![Two]
strField3 = rs![Three]
strField4 = rs![Four]
End If 'End If strNewField1 = strField1 Then
End If 'End If intRecordCount = 1
.MoveNext 'Move to next record in recordset.
Loop 'Back to 'Do While' to check if we are at the end of the file.
'Create SQL for Last Row of data that is still stored even though Access found the EOF.
strSQL = "INSERT INTO AA_Test_Write (One, Two, Three, Four) "
strSQL = strSQL & "VALUES (" & "'" & strField1 & "'" & ", " & "'" & strField2 & "'" & ", " & "'" & strField3 & "'" & ", " & "'" & strField4 & "'" & "); "
'Execute Insert SQL.
DoCmd.RunSQL strSQL
Exit_Get_DB_Values:
If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If
Set db = Nothing
Exit Function
Error_Handle:
Resume Exit_Get_DB_Values
End With
End Function
I hope this solves your problem or at least that you can use this as a starting point.
Let me know if there are problems with this!!
All the best!
