Hello. I have been testing some code I found online that is supposed to take entire column of data in a table or query and convert it to a single string.
With a command button, I set the value of a textbox to contain the result of the function.
Here is what I have:
Code:
Private Sub Command117_Click()
Me![Work Desc] = CombineList("WeeklyTimesheetQueryResults", "Description", ";")
End Sub
...and the function:
Code:
Option Compare Database
Function CombineList(strSource As String, strField As String, strDelim As String, Optional strTextQual As Variant) As String
' Combines a single column from multiple records into a single string
' Arguments
' strSource = name of query or table
' strField = name of field you want to combine
' strDelim = delimiter to use to separate each value
' strTextQual = text qualifer to use around each field (optional)
Dim myDB As DAO.Database
Dim myRS As DAO.Recordset
Dim myRecCount As Long
Dim myTempString As String
Set myDB = CurrentDb
Set myRS = myDB.OpenRecordset(strSource, dbOpenDynaset)
myRecCount = DCount(strField, strSource)
If myRecCount > 0 Then
With myRS
.MoveFirst
Do While Not .EOF
myTempString = myTempString & strTextQual & myRS(strField) & strTextQual & strDelim
.MoveNext
Loop
End With
End If
Set myRS = Nothing
Set myDB = Nothing
If Len(myTempString) > 0 Then CombineList = Left(myTempString, Len(myTempString) - 1)
End Function
The type mismatch error comes up with the following line:
Code:
myTempString = myTempString & strTextQual & myRS(strField) & strTextQual & strDelim
what might I be doing wrong here?
Thank you in advance for any suggestions.