My vba code isn't picking up all the records. I'm not sure what is wrong with code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michelle Chase
    New Member
    • Oct 2010
    • 1

    My vba code isn't picking up all the records. I'm not sure what is wrong with code

    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
    Last edited by MMcCarthy; Oct 19 '10, 07:19 PM. Reason: added code tags
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Try to break your code into smaller sections and test each bit.
    You are not helping youself or us by displaying the whole program
    and not identifying where or what the problem is

    Comment

    Working...