I've got a table in Microsoft Access with two columns. I wish to Group the list by one of them and the Information of the other column should be written separated by a slash. My code works, but it takes very long (more than two hours). Does anybody has an idea, how to handle this Problem in another way?
I declared a function (see below the big code). In a Query I open this function with SQL
Select SQLListe("SELECT [column2] FROM [table_name] WHERE [column1] = '" & [column1] & "'";"/";"/") AS Result FROM [table_name]
As I said, it takes really long, amongst others a lot of rows in the table. But maybe someone has an idea.
Thanks!
Option Compare Database
Public Function SQLListe(ByVal SQL As String, _
Optional ByVal SepR As String = ";", _
Optional ByVal SepF As String = ";", _
Optional ByVal NoNullFields As Boolean = True) _
As String
Dim rs As DAO.Recordset
Dim i As Long
Dim Res As String
Dim Tmp As String
Set rs = CurrentDb.OpenRecordset(SQL, dbOpenDynaset)
On Error Resume Next
If Err.Number <> 0 Then
Res = "#Fehler"
Err.Clear
Else
On Error GoTo 0
Res = ""
Do While Not rs.EOF
Tmp = ""
For i = 0 To rs.Fields.Count - 1
If Not (NoNullFields And IsNull(rs(i))) Then
Tmp = Tmp & SepF & rs(i)
End If
Next
If Tmp <> "" Then
Res = Res & SepR & Mid(Tmp, Len(SepF) + 1)
End If
rs.MoveNext
Loop
If Res <> "" Then
Res = Mid(Res, Len(SepR) + 1)
End If
End If
If Not rs Is Nothing Then rs.Close: Set rs = Nothing
SQLListe = Res
End Function