ChristineMD
Board Regular
- Joined
- Jul 29, 2008
- Messages
- 53
I have an access (2010) database where a vendor whom we no longer deal with wrote a little piece of code to combine order details from multiple rows into a single MEMO field. So, multiple records into a single record.
In the source table, no field of order detail exceeds 255 characters, but the field is defined as a memo field, nonetheless.
The VB code writes the combined data out to a different table, with the combined order details also going into a MEMO field. It works fine. I never see any data truncations.
I copied this module into another database and modified it very slightly - i.e. changed the function, field(s) and table names. And now it’s truncating every combined field @ 255 chars. The order details in the original table are in a memo field (also never exceed 255 chars) and the table the vb writes to also is a memo field for this data.
For the LIFE of me I cannot see why it is not working th same… WHY??
Any help will be appreciated, please let me know if there's any additional info I can provide!!
This code WORKS fine:
This code does NOT, it truncates the field @ 255 chars.
In the source table, no field of order detail exceeds 255 characters, but the field is defined as a memo field, nonetheless.
The VB code writes the combined data out to a different table, with the combined order details also going into a MEMO field. It works fine. I never see any data truncations.
I copied this module into another database and modified it very slightly - i.e. changed the function, field(s) and table names. And now it’s truncating every combined field @ 255 chars. The order details in the original table are in a memo field (also never exceed 255 chars) and the table the vb writes to also is a memo field for this data.
For the LIFE of me I cannot see why it is not working th same… WHY??
Any help will be appreciated, please let me know if there's any additional info I can provide!!
This code WORKS fine:
Code:
Public Function CreateExportO30102() As Boolean
On Error Resume Next
Dim db As DAO.Database, rst As DAO.Recordset, sSQL As String
Dim strOrder As String, strEmail As String, strName As String, strDescription As String
Set db = CurrentDb()
'Call RecreateTables(db)
sSQL = "DELETE FROM O30102_for_export"
db.Execute sSQL
sSQL = "SELECT order_no, email, name, description FROM O30102_EMail ORDER BY email, order_no ASC"
Set rst = db.OpenRecordset(sSQL, dbOpenSnapshot)
If Not rst.BOF And Not rst.EOF Then
rst.MoveFirst
strOrder = rst!Order_No
strEmail = rst!Email
strName = rst!Name
strDescription = rst!Description
rst.MoveNext
Do Until rst.EOF
If strEmail = rst!Email Then
strOrder = strOrder & ", " & rst!Order_No
strDescription = strDescription & Chr(10) & rst!Description
Else
sSQL = "INSERT INTO O30102_for_export (order_no, Email, Name, Description) VALUES('" & strOrder & "','" & strEmail & "','" & strName & "','" & strDescription & "')"
db.Execute sSQL
strOrder = rst!Order_No
strEmail = rst!Email
strName = rst!Name
strDescription = rst!Description
End If
rst.MoveNext
Loop
' Insert Last Record
sSQL = "INSERT INTO O30102_for_export (order_no, Email, Name, Description) VALUES('" & strOrder & "','" & strEmail & "','" & strName & "','" & strDescription & "')"
db.Execute sSQL
End If
Set rst = Nothing
Set db = Nothing
End Function
Code:
Public Function CreateExport() As Boolean
On Error Resume Next
Dim db As DAO.Database, rst As DAO.Recordset, sSQL As String
Dim strEmail As String, strline As String
Set db = CurrentDb()
'Call RecreateTables(db)
sSQL = "DELETE FROM export"
db.Execute sSQL
sSQL = "SELECT Email, line FROM mtOrdShp ORDER BY email ASC"
Set rst = db.OpenRecordset(sSQL, dbOpenSnapshot)
If Not rst.BOF And Not rst.EOF Then
rst.MoveFirst
strEmail = rst!Email
strline = rst!Line
rst.MoveNext
Do Until rst.EOF
If strEmail = rst!Email Then
strline = strline & Chr(10) & rst!Line
Else
sSQL = "INSERT INTO export (Email, line) VALUES('" & strEmail & "','" & strline & "')"
db.Execute sSQL
strEmail = rst!Email
strline = rst!Line
End If
rst.MoveNext
Loop
' Insert Last Record
sSQL = "INSERT INTO export (Email, line) VALUES('" & strEmail & "','" & strline & "')"
db.Execute sSQL
End If
Set rst = Nothing
Set db = Nothing
End Function