catsoncars
New member
- Local time
- Today, 10:16
- Joined
- Feb 2, 2010
- Messages
- 6
My first post and I am pretty clueless so be nice 
I have a recordset
Set rst = db.OpenRecordset("SELECT qryWorkInfoText.WIIncidentID, qryWorkInfoText.WIText FROM qryWorkInfoText;")
The WIIncidentID is just a alphanumeric number and WIText is a string. I need to take multiple rows of WIText with the same WIIncidentID and combine WIText into a single field, stringing one right after the other to create a pseudo comments field. I had that part working but sometimes the resulting comments field exceeded 1200 characters and the SQL would bomb (too long) when trying to load the data into CombWork below. I do have CombWorkInfo set as a memo so it is the actual strWIText that is to long for the sql statement.
After reading many, many posts I thought an array would work but have no idea how to read enough records from the recordset for each WIIncidentID as they vary in number of rows.
Basically I want to read the first rows that have the same WIIncidentID, put those text strings in an array and then load that new record into CombWork. Go back to the recordset and get the next WIIncidentID and text strings, and continue until they are all read and loaded.
If there is an easier way, great, but I really need help.
This is the code I have which bombs on the insert when the comments are too long.
strWIText = strWIText & " " & Nz(rst!WIText, vbNullString)
strIncidentID = rst![WIIncidentId]
'
'move to next record
'
rst.Move 1
'
If rst.EOF Then Exit Sub
'
Loop Until rst![WIIncidentId] <> strIncidentID
DoCmd.RunSQL "INSERT INTO CombWork ( WIIncidentID, CombWorkInfo ) SELECT '" & strIncidentID & "','" & strWIText & "'"
'
'reset comments
'
strWIText = vbNullString
'
Loop Until rst.EOF

I have a recordset
Set rst = db.OpenRecordset("SELECT qryWorkInfoText.WIIncidentID, qryWorkInfoText.WIText FROM qryWorkInfoText;")
The WIIncidentID is just a alphanumeric number and WIText is a string. I need to take multiple rows of WIText with the same WIIncidentID and combine WIText into a single field, stringing one right after the other to create a pseudo comments field. I had that part working but sometimes the resulting comments field exceeded 1200 characters and the SQL would bomb (too long) when trying to load the data into CombWork below. I do have CombWorkInfo set as a memo so it is the actual strWIText that is to long for the sql statement.
After reading many, many posts I thought an array would work but have no idea how to read enough records from the recordset for each WIIncidentID as they vary in number of rows.
Basically I want to read the first rows that have the same WIIncidentID, put those text strings in an array and then load that new record into CombWork. Go back to the recordset and get the next WIIncidentID and text strings, and continue until they are all read and loaded.
If there is an easier way, great, but I really need help.
This is the code I have which bombs on the insert when the comments are too long.
strWIText = strWIText & " " & Nz(rst!WIText, vbNullString)
strIncidentID = rst![WIIncidentId]
'
'move to next record
'
rst.Move 1
'
If rst.EOF Then Exit Sub
'
Loop Until rst![WIIncidentId] <> strIncidentID
DoCmd.RunSQL "INSERT INTO CombWork ( WIIncidentID, CombWorkInfo ) SELECT '" & strIncidentID & "','" & strWIText & "'"
'
'reset comments
'
strWIText = vbNullString
'
Loop Until rst.EOF