Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-20
9
Medium Priority
?
616 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

715 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