Rx_
Nothing In Moderation
- Local time
- Today, 01:07
- Joined
- Oct 22, 2009
- Messages
- 2,803
It is the same... but a little different twist.
Comments are in a memo field. Many comments to one customerID (i.e. Wells ID).
The report output is Excel 2010. The customer wants all the comments concat into one large comment that will surpass 255 characters.
The preious post - the CopyFromRecordset or any other Access function limits the data transfer of a recordset to 255 characters. So, a vba function was created. This function allows all the memo fields to be strung together into one large sting variable. And the string can be put into an Excel 2010 cell.
The code worked great. It took several records and added the comment fields together for a string larger than 255 characters.
Problem:
Turns out that some of the individual comments are larger than 255 characters. The output on my form in a text box shows around 285 on some comments. But, the code copies the first 255 then adds square boxes and strange characters. The debug.Print helped me locate some long-winded comment fields. Sure enough, the strange characters start at position 255.
Question:
Any ideas if it is possible to parce an individual field >255 characters and then concat them back together?
Or, is the OpenRecordset part of the limitation?
The debug window shows long strings - thought the line feed was just a debug window view issue. Turns out that the String variable is doing something evil.
Comments are in a memo field. Many comments to one customerID (i.e. Wells ID).
The report output is Excel 2010. The customer wants all the comments concat into one large comment that will surpass 255 characters.
The preious post - the CopyFromRecordset or any other Access function limits the data transfer of a recordset to 255 characters. So, a vba function was created. This function allows all the memo fields to be strung together into one large sting variable. And the string can be put into an Excel 2010 cell.
The code worked great. It took several records and added the comment fields together for a string larger than 255 characters.
Problem:
Turns out that some of the individual comments are larger than 255 characters. The output on my form in a text box shows around 285 on some comments. But, the code copies the first 255 then adds square boxes and strange characters. The debug.Print helped me locate some long-winded comment fields. Sure enough, the strange characters start at position 255.
Question:
Any ideas if it is possible to parce an individual field >255 characters and then concat them back together?
Or, is the OpenRecordset part of the limitation?
Code:
Function ConcatComments(intPrimaryKeyID As Long) As String ' Wells Primary ID passed in
Dim dbCommentsCodes As DAO.Database
Dim rsCommentsCodes As DAO.Recordset
Dim CommentString As String ' Output String
Dim strCriteria As String, strsCommentsCodesQL As String
' Change SQL statement to accept intPrimaryKeyID as shown below
10 strsCommentsCodesQL = "SELECT CStr([Date]) & ' : ' & [Comments] & ' |' AS Comment " & _
"FROM Wells INNER JOIN Comments ON Wells.ID_Wells = Comments.ID_Wells " & _
"WHERE (((Wells.ID_Wells) = " & intPrimaryKeyID & ")) " & _
"ORDER BY Comments.Date DESC , Wells.ID_Wells;"
20 On Error GoTo Err_ConcatComments
30 CommentString = ""
40 Set dbCommentsCodes = CurrentDb
50 Set rsCommentsCodes = dbCommentsCodes.OpenRecordset(strsCommentsCodesQL, dbOpenSnapshot) ' snapshots run faster
60 With rsCommentsCodes
70 If .RecordCount <> 0 Then
80 Do While Not rsCommentsCodes.EOF
90 CommentString = CommentString & rsCommentsCodes("Comment") & " " ' <-- Field to concat and delimiter
If Len(rsCommentsCodes("Comment")) > 250 Then
Debug.Print intPrimaryKeyID & " STRING IS " & Len(CommentString) & " commen is " & Len(rsCommentsCodes("Comment"))
End If
100 .MoveNext
110 Loop
120 End If
130 End With
Exit_ConcatComments:
'ConcatComments = Null
150 If Not rsCommentsCodes Is Nothing Then
160 rsCommentsCodes.Close
170 Set rsCommentsCodes = Nothing
180 End If
190 Set dbCommentsCodes = Nothing
200 Exit Function
Err_ConcatComments:
210 Resume Exit_ConcatComments
End Function
Last edited: