Link to home
Start Free TrialLog in
Avatar of billcute
billcute

asked on

Removing numbering in Memo field

The attached code in the Snippet adds numbering to the notes in the Memo field. Now, I will like to remove the numbering option and the leave the rest of the code intact. How can I do that?
Private Sub cboSDSubject_AfterUpdate()
        Dim arr
        Dim inti As Integer
            ' Add combo value
            If Len(Nz(Me.memPERANotes)) > 0 Then
                Me.memPERANotes = vbCrLf & Me.memPERANotes & vbCrLf & Me.cboSDSubject.Column(1)
        Else
'                Me.memPERANotes = vbCrLf & Me.cboSDSubject.Column(1)
            End If
                ' remove empty rows
            While InStr(Me.memPERANotes, vbCrLf & vbCrLf) > 0
                Me.memPERANotes = Replace(Me.memPERANotes, vbCrLf & vbCrLf, vbCrLf)
            Wend
                ' split
                arr = Split(Me.memPERANotes, vbCrLf)
                Me.memPERANotes = ""
            For inti = 1 To UBound(arr)
                ' no value or wrong value, test for . in first three positions (allows for 1. to 99.)
            If InStr(arr(inti), ".") > 0 And InStr(arr(inti), ".") <= 3 Then
                ' replace sequence
                Me.memPERANotes = Me.memPERANotes & vbCrLf & inti & Mid(arr(inti), InStr(arr(inti), "."))
        Else
                ' place new sequence
                Me.memPERANotes = Me.memPERANotes & vbCrLf & inti & ". " & arr(inti)
            End If
        Next
                ' remove first vbCRLF
                Me.memPERANotes = Mid(Me.memPERANotes, 3)
End Sub

Open in new window

Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Try this:
Private Sub cboSDSubject_AfterUpdate()
        Dim arr
        Dim inti As Integer
            ' Add combo value
            If Len(Nz(Me.memPERANotes)) > 0 Then
                Me.memPERANotes = vbCrLf & Me.memPERANotes & vbCrLf & Me.cboSDSubject.Column(1)
        Else
'                Me.memPERANotes = vbCrLf & Me.cboSDSubject.Column(1)
            End If
                ' remove empty rows
            While InStr(Me.memPERANotes, vbCrLf & vbCrLf) > 0
                Me.memPERANotes = Replace(Me.memPERANotes, vbCrLf & vbCrLf, vbCrLf)
            Wend
                ' split
                arr = Split(Me.memPERANotes, vbCrLf)
                Me.memPERANotes = ""
 
                ' remove first vbCRLF
                Me.memPERANotes = Mid(Me.memPERANotes, 3)
End Sub

Open in new window

Avatar of billcute
billcute

ASKER

I pasted the amended code and tried it but it did not add  the notes in combo (cboSDSubject) into the memo field (memPERANotes).

Normally user selects an item from a list in combo (cboSDSubject) and that selection is then pasted in the memo field  memPERANotes with numbering and one space. It is that number and the space in front of it that I am trying to eliminate.

Right now, the amended code is not even pasting the selected item from the combo into the memo field.
I also noted that I mistakenly remarked the line code shown below from original question, I have now remove the "rem" in front of the line code.

                Me.memPERANotes = vbCrLf & Me.cboSDSubject.Column(1)
I'm not entirely clear on what you mean by "remove numbering" ... the Loop I removed was where the numbering was occurring (I believe) and I removed that loop.

Below I added it back, but removed the Loop ... if this doesn't work you'll need to explore this a bit further and let us know exactly where the "numbering" is occurring ...
Private Sub cboSDSubject_AfterUpdate()
        Dim arr
        Dim inti As Integer
            ' Add combo value
            If Len(Nz(Me.memPERANotes)) > 0 Then
                Me.memPERANotes = vbCrLf & Me.memPERANotes & vbCrLf & Me.cboSDSubject.Column(1)
        Else
'                Me.memPERANotes = vbCrLf & Me.cboSDSubject.Column(1)
            End If
                ' remove empty rows
            While InStr(Me.memPERANotes, vbCrLf & vbCrLf) > 0
                Me.memPERANotes = Replace(Me.memPERANotes, vbCrLf & vbCrLf, vbCrLf)
            Wend
                ' split
                arr = Split(Me.memPERANotes, vbCrLf)
                Me.memPERANotes = ""
                Me.memPERANotes = Me.memPERANotes 
        Next
                ' remove first vbCRLF
                Me.memPERANotes = Mid(Me.memPERANotes, 3)
End Sub

Open in new window

Ok:
I tried the last I received a Run-Time Error '94': Invalid use of Null"

on:
                 ' split
                arr = Split(Me.memPERANotes, vbCrLf)       '<--- Error line
Ok, here is my link to the original code assisted by "nico5038"  on 01.29.2006 at 04:57PM EST, ID: 15819370

LSMConsulting:
Did you see my last two comments?
ASKER CERTIFIED SOLUTION
Avatar of oldmanbim
oldmanbim
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
However,

If the only reason to remove the numbers is b/c the form doesn't update the numbers properly, one can do that with only a little extra code.

The attached should be close to what one might want.
Private Const DELIM As String = ". "
 
 
Private Sub cboSDSubject_AfterUpdate()
    ' Append data to memPERANotes   
    Me.memPERANotes = Me.memPERANotes & vbCrLf & Me.cboSDSubject.Column(1)
    ' Let the AfterUpdate routine fix issues
    memPERANotes_AfterUpdate
 
End Sub
 
Private Sub memPERANotes_AfterUpdate()
    Dim arr As Variant
    Dim i As Integer
    Dim posDelim As Integer
    
    ' remove empty rows
    While InStr(Me.memPERANotes, vbCrLf & vbCrLf) > 0
        Me.memPERANotes = Replace(Me.memPERANotes, vbCrLf & vbCrLf, vbCrLf)
    Wend
    ' Remove empty first row
    If InStr(1, Me.memPERANotes, vbCrLf) = 1 Then
        Me.memPERANotes = Mid(Me.memPERANotes, 3)
    End If
    
    ' Split each line to a separate array element
    arr = Split(Me.memPERANotes, vbCrLf)
    
    ' Blank me.memPERANotes
    Me.memPERANotes = ""
    
    For i = 0 To UBound(arr)
        ' Get rid of any extra spaces
        arr(i) = Trim(arr(i))
        
        ' Find the position of the deliminator
        posDelim = InStr(1, arr(i), DELIM)
        If posDelim > 0 Then
            '*** Has Delim
            ' Is there only a number before the deliminator?
            If IsNumeric(left(arr(i), posDelim - 1)) Then
                ' Get rid of everything before the deliminator
                arr(i) = Mid(arr(i), posDelim + Len(posDelim))
            End If
        End If
        Me.memPERANotes = Me.memPERANotes & vbCrLf & i + 1 & DELIM & arr(i)
    Next
    
    ' remove first vbCrLf
    Me.memPERANotes = Mid(Me.memPERANotes, 3)
 
End Sub

Open in new window

oldmanbim:
Thanks for the extra effort.
oldmanbim:
Your suggested code under ID: 22818786 did the trick.

As for  "nico" original code, it works great. I have an isolated case where I did not need the numbering...but thanks for the additional suggestion.

Regards
Bill
Excellent