Appending text to a memo field(long text) on SQL server (1 Viewer)

mrtn

Registered User.
Local time
Today, 10:57
Joined
Dec 16, 2010
Messages
43
Hi all

I am trying to append text to a memo-style field which already holds some text and failing miserably.

Here's extract from my code:
Code:
Set conn = New ADODB.Connection
        Set rs = New ADODB.Recordset
    
        rs.CursorLocation = adUseClient
        
        conn.Open strConnection
        
        rs.Open "SELECT cast(dbo.Review_notes.Note_Generic as text) as NoteGeneric FROM dbo.Review_notes WHERE ReviewID = " & lRevID & ";", conn, adOpenDynamic, adLockOptimistic
            
            'update existing note
            sNote = rs.Fields("NoteGeneric").GetChunk(rs.Fields("NoteGeneric").ActualSize)
            Debug.Print sNote
            rs.Fields("NoteGeneric").AppendChunk "some text"
            rs.Update

Whilst I am able to get the existing value, the appendchunk doesn't seem to do anything...
 

mrtn

Registered User.
Local time
Today, 10:57
Joined
Dec 16, 2010
Messages
43
Right, I seem to have found a workaround - posting my code below just in case somebody has a similar problem.

The solution involves pulling an existing note and appending a note via separate recordsets. Not the prettiest of solutions but does the job:

Code:
Set conn = New ADODB.Connection
        Set rs = New ADODB.Recordset
    
        rs.CursorLocation = adUseClient
        
        conn.Open strConnection
        
        'pull existing note
        rs.Open "SELECT cast(dbo.Review_notes.Note_Generic as text) as NoteGeneric FROM dbo.Review_notes WHERE ReviewID = " & lRevID & ";", conn, adOpenDynamic, adLockOptimistic
        
        If rs.EOF = False Then
        
            '### update existing note
            'pull existing note first
            If rs.Fields("NoteGeneric").ActualSize > 0 Then
            
                sNote = rs.Fields("NoteGeneric").GetChunk(rs.Fields("NoteGeneric").ActualSize)
        
            Else
            
                sNote = ""
                
            End If
            
            rs.Close
            
            'append new note (only if if doesn't exist in the note already)
            If InStr(1, sNote, sRevNote) = 0 Then
            
                rs.Open "SELECT * FROM dbo.Review_notes WHERE ReviewID = " & lRevID & ";", conn, adOpenDynamic, adLockOptimistic
        
                rs.Fields("Note_Generic").AppendChunk sRevNote & vbNewLine & vbNewLine
                rs.Fields("Note_Generic").AppendChunk sNote
                
                rs.Update
                rs.Close
                
            End If

        Else

            rs.Close
        
            'append new note
            rs.Open "SELECT * FROM dbo.Review_notes;", conn, adOpenDynamic, adLockOptimistic
            
            rs.AddNew
            
            rs.Fields("ReviewID").Value = lRevID
            rs.Fields("Note_Generic").AppendChunk sRevNote & vbNewLine & vbNewLine
            rs.Fields("Reviewee").Value = Me.Reviewee
            rs.Fields("NoteDateStamp").Value = Me.txt_DateStamp
            
            rs.Update
            rs.Close
        
        End If
        
        conn.Close
        
        Set conn = Nothing
        Set rs = Nothing
 

Users who are viewing this thread

Top Bottom