Solved

Update Query to Delete everything to thr right: 4th comma

Posted on 2007-03-20
9
610 Views
Last Modified: 2012-08-14
Access 2003

I need an Update query that will delete everything to the left of the 4th comma in a a string.
=====================================
Or maybe I need a function like this Revised:

Function getword(mystring As String) As String
Dim v As Variant
v = Split(Left([mystring], InStr([mystring], ",") - 1), " ")
getword = v(UBound(v))
End Function

UPDATE tblRichText set fldFirstComma = getword(fldRichText)
==========================================

Sometimes the field may not have 4 commas, or  No commas at all.

Thanks
fordraiders


0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18761977
Function getword(mystring As String) As String
dim vArr
vArr = Split(mystring, " ", 5)
getword=vArr(ubound(vArr))

end function
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18761992
sorry, separator is comma

Function getword(mystring As String) As String
dim vArr
vArr = Split(mystring, ",", 5)
getword=vArr(ubound(vArr))

end function

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18761997
<Sometimes the field may not have 4 commas, or  No commas at all.>
what do you want to do if this is the case?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18762035


Function getWord(s As String) As String
Dim  xArr
xArr = Split(s, ",")
If UBound(xArr) < 4 Then
    'comma is less then 4
    getWord = "we have less then 4 commas"
    Else
    xArr = Split(s, ",", 5)
    getWord = xArr(UBound(xArr))
End If
End Function


0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18762047
update tableName
set [fieldName]=getword([fieldName])
0
 
LVL 3

Author Comment

by:fordraiders
ID: 18762117
Sorry, I meant find the 4th comma and delete everyting to the right !
0
 
LVL 3

Author Comment

by:fordraiders
ID: 18762135
<Sometimes the field may not have 4 commas, or  No commas at all.>
what do you want to do if this is the case?

bypass the record
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 18762801
try this

Function getWord(s As String) As String
Dim xArr, j, sTemp
xArr = Split(s, ",")
If UBound(xArr) < 4 Then
    'comma is less then 4
    getWord = s
    Else
    xArr = Split(s, ",", 5)
    For j = 0 To UBound(xArr) - 1
        sTemp = sTemp & xArr(j) & ","
    Next
    getWord = Left(sTemp, Len(sTemp) - 1)
End If
End Function
0
 
LVL 3

Author Comment

by:fordraiders
ID: 18763214
Thanks cap !
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question