I am trying to use the following code to report two values into one line.It works fine except for the fact that when it writes the last record, it errors out with 'No current record' error. Could someone help me amend the code to prevent this error from happening.
Public Sub combine_descriptions()
'turn off warning dialog
DoCmd.SetWarnings (False)
Dim rst As Recordset
Dim strCurrentCustomer As String
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tbl ORDER BY Customer")
strCurrentCustomer = vbNullString
'set comments back to null
strcomments = vbNullString
Do
Do
strcomments = strcomments & " " & Nz(rst!comments, vbNullString)
strCurrentCustomer = rst!customer
'move to next record
rst.Move 1
Loop Until rst!customer <> strCurrentCustomer
DoCmd.RunSQL "INSERT INTO newtablename ( Customer, Comments ) SELECT '" & strCurrentCustomer & "','" & strcomments & "'"
'reset comments
strcomments = vbNullString
Loop Until rst.EOF
rst.Close
Set rst = Nothing
'turn dialogs back on
DoCmd.SetWarnings (True)
End Sub
Public Sub combine_descriptions()
'turn off warning dialog
DoCmd.SetWarnings (False)
Dim rst As Recordset
Dim strCurrentCustomer As String
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tbl ORDER BY Customer")
strCurrentCustomer = vbNullString
'set comments back to null
strcomments = vbNullString
Do
Do
strcomments = strcomments & " " & Nz(rst!comments, vbNullString)
strCurrentCustomer = rst!customer
'move to next record
rst.Move 1
Loop Until rst!customer <> strCurrentCustomer
DoCmd.RunSQL "INSERT INTO newtablename ( Customer, Comments ) SELECT '" & strCurrentCustomer & "','" & strcomments & "'"
'reset comments
strcomments = vbNullString
Loop Until rst.EOF
rst.Close
Set rst = Nothing
'turn dialogs back on
DoCmd.SetWarnings (True)
End Sub