TRIM last 4 caracters from String

joeserrone

The cat of the cul-de-sac
Local time
Today, 01:48
Joined
Dec 17, 2006
Messages
164
I currently have the following code listed below behind a multi-select list box that creates a string and places it on a text box that I am trying to use for a query criteria. After the string loops I want to be able to trim the last 4 character. My Results right now are like this:
Balance OR Balance Recovery OR

I want them to appear in my text box like this:
Balance OR Balance Recovery

---------------------------------------------------------

Private Sub Command45_Click()
Dim lngLoop As Long
Dim strIDs As String

If ListCategoryEdit.ItemsSelected.Count > 0 Then
strIDs = ""
For lngLoop = 0 To ListCategoryEdit.ItemsSelected.Count - 1
strIDs = strIDs & "" & ListCategoryEdit.ItemData(ListCategoryEdit.ItemsSelected(lngLoop)) & " OR "

Next lngLoop

txtQueryCriteria = strIDs
DoCmd.OpenQuery "EditQuery"
Else
txtQueryCriteria = ""
MsgBox "No names are selected!", vbExclamation
End If
End Sub
 
you could try using

left(yourfieldyouwanttoreturn, len(yourfieldyouwanttoreturn)-4))

more specifically

strIDs= left(strIDs, len(strIDs)-4)
 
Last edited:
I currently have the following code listed below behind a multi-select list box that creates a string and places it on a text box that I am trying to use for a query criteria. After the string loops I want to be able to trim the last 4 character. My Results right now are like this:
Balance OR Balance Recovery OR

I want them to appear in my text box like this:
Balance OR Balance Recovery

---------------------------------------------------------

Private Sub Command45_Click()
Dim lngLoop As Long
Dim strIDs As String

If ListCategoryEdit.ItemsSelected.Count > 0 Then
strIDs = ""
For lngLoop = 0 To ListCategoryEdit.ItemsSelected.Count - 1
strIDs = strIDs & "" & ListCategoryEdit.ItemData(ListCategoryEdit.ItemsSelected(lngLoop)) & " OR "

Next lngLoop

txtQueryCriteria = strIDs
DoCmd.OpenQuery "EditQuery"
Else
txtQueryCriteria = ""
MsgBox "No names are selected!", vbExclamation
End If
End Sub

you could try using

left(yourfieldyouwanttoreturn, len(yourfieldyouwanttoreturn)-4))

Rainman is right, but woulodn't it be easier to just NOT include the extra 4 characters in the first place?
Code:
If ListCategoryEdit.ItemsSelected.Count > 0 Then
    strIDs = ""
    For lngLoop = 0 To ListCategoryEdit.ItemsSelected.Count - 1
        strIDs = strIDs & "" & ListCategoryEdit.ItemData(ListCategoryEdit.ItemsSelected(lngLoop))
 
        If lngLoop < ListCategoryEdit.ItemsSelected.Count - 1 Then
            strIDs = strIDs & " OR "
        End If
 
    Next lngLoop
End If
 

Users who are viewing this thread

Back
Top Bottom