Solved

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

Posted on 2007-03-20
9
593 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 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

830 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