Code:
Option Compare Database
'this one is to use to concatenate the fields
Function combine_descriptions()
'turn off warning dialog
DoCmd.SetWarnings (False)
Dim rst As Recordset
Dim strCurrentitemnumber As String
' Gets all items and comment text within the items table
Set rst = CurrentDb.OpenRecordset("SELECT * FROM items ORDER BY itemnumber")
strCurrentitemnumber = vbNullString
'set comments back to null
strcommenttext = vbNullString
Do
Do
'combines the comment text by item number
strcommenttext = strcommenttext & " " & Nz(rst!CommentText, vbNullString)
strCurrentitemnumber = rst!ItemNumber
'move to next record
rst.Move 1
'loop to next item number
Loop Until rst!ItemNumber <> strCurrentitemnumber
'combines into one line the comment text for each item number
DoCmd.RunSQL "INSERT INTO itemdescrip( itemnumber, len(commenttext)< 255 SELECT '" & strCurrentitemnumber & "','" & strcommenttext & "'"
'reset comments
strcommenttext = vbNullString
'loop through all item numbers
Loop Until rst.EOF
rst.Close
Set rst = Nothing
'turn dialogs back on
DoCmd.SetWarnings (False)
End Function
Comment