Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / February 2005

Tip: Looking for answers? Try searching our database.

Parse one field's data into multiple fields

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jlicciardi@mssystems.com - 21 Feb 2005 20:51 GMT
I have a table with a field that has ( a sample )
13767;38355;520270-1;
44795;38355;110818;
13981;38355;563550;

as data. I need to extract the last set of numbers in each row.
I have tried right$([name],len([name])- instr(1,[name],";")-1)
but to no avail

Please help
Darryl Kerkeslager - 21 Feb 2005 22:54 GMT
> I have a table with a field that has ( a sample )
> 13767;38355;520270-1;
[quoted text clipped - 4 lines]
> I have tried right$([name],len([name])- instr(1,[name],";")-1)
> but to no avail

You may not want to use Right() if your field has 'irregular' data like  
your first one above.  You should use the Mid() function.  Does your third  
data segment always begin at the 13th position ... or is the best you can  
say that it is always after the second semi-colon?

Before you answer that, ask yourself, is there any way to NOT put this  
data in the same field to begin with?  It looks like it should be in three  
separate fields.  Second, is there any way to eliminate irregular data,  
which would certainly make it easier to extract.

Darryl Kerkeslager
pietlinden@hotmail.com - 22 Feb 2005 02:25 GMT
jliccia...@mssystems.com wrote:
> I have a table with a field that has ( a sample )
> 13767;38355;520270-1;
[quoted text clipped - 6 lines]
>
> Please help

Hope this doesn't have to be fast... I could do it with strReverse and
then snip off the first semi-colon and then take everything between
position 1 and the next semi-colon, but that was way too much of a
headache.  Will this work for ya?

Option Compare Database

Public Function LastChunkOfString(ByVal strText As String, ByVal
strDelim As String) As Variant
'Sample inputs and outputs... note, these are TEXT.
' 13981;38355;563550;
'returns: 563550
' 13767;38355;520270-1;
'returns: 520270-1
' 44795;38355;110818;
'returns: 110818

   Dim ChunkString As Variant
   ChunkString = Split(strText, strDelim, , vbTextCompare)
   LastChunkOfString = ChunkString(UBound(ChunkString) - 1)

End Function

so I _guess_ you could do it in SQL...

SELECT... ChunkString(UBound(Split(strText, strDelim, , vbTextCompare))
- 1)
FROM...
WHERE...

but I didn't mess with that... that's the fun you get to have!

BTW, I agree with Darryl - the best way out of this mess in the future
is to not get yourself into it in the first place.  Break up your data
as small as you can BEFORE you enter it, and you won't have to do these
things to begin with.
jlicciardi@mssystems.com - 22 Feb 2005 14:48 GMT
The third data segment doesn't always start at the 13th position,
sometimes there are more than 3 segments. The data is system generated.
There is no way to eliminate the irregular data.
thanks
Your function LastofChunk works fine. Thanks
> jliccia...@mssystems.com wrote:
> > I have a table with a field that has ( a sample )
[quoted text clipped - 44 lines]
> as small as you can BEFORE you enter it, and you won't have to do these
> things to begin with.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.