Solved

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

Posted on 2007-03-20
9
564 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
  • 6
  • 3
9 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
Function getword(mystring As String) As String
dim vArr
vArr = Split(mystring, " ", 5)
getword=vArr(ubound(vArr))

end function
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility
<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
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility


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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
update tableName
set [fieldName]=getword([fieldName])
0
 
LVL 3

Author Comment

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

Author Comment

by:fordraiders
Comment Utility
<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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
Thanks cap !
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now