473,396 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I use the Split Function?

283 100+
Hello all,

I am trying to use the split function to seperate out some information in my table. I keep reading up on how to get this to work but every time i try it its not working. I either get errors or a pop up box asking me to enter in a value and when i do i just get zeros back.

What I have is a report I get sent that is in Excel format. Imported it in to a table in Access so I can do more with it. One of the columns has two pieces of information in it that I want to seperate in to two seperate columns.

What I did was I made a query that runs off of the table. In the query in the Field box I pluged in this code
Expand|Select|Wrap|Line Numbers
  1. Expr1: Val(Left([SHIPPER REFERENCE#],InStr([SHIPPER REFERENCE#]," ")))
Im not sure if i am putting this in the wrong spot or i have something typed wrong but any help would be great. Also i have tried various additions by putting a +1 or a -1 in at the end and still nothing.
Mar 24 '10 #1

✓ answered by missinglinq

You're right, NeoPa! In the Query Grid the calculated fields would be
Expand|Select|Wrap|Line Numbers
  1. FirstField: Left([OriginalField],InStrRev([OriginalField]," ")-1)
  2.  
  3. SecondField: Right([OriginalField],Len([OriginalField])-InStrRev([OriginalField]," "))
In SQL it would be
Expand|Select|Wrap|Line Numbers
  1. SELECT YourTableName.OriginalField, Left([OriginalField],InStrRev([OriginalField]," ")-1) AS FirstField, Right([OriginalField],Len([OriginalField])-InStrRev([OriginalField]," ")) AS SecondField
  2. FROM YourTableName;
Linq ;0)>

9 4593
NeoPa
32,556 Expert Mod 16PB
This doesn't look too bad, but you haven't handled the situation where there is no space in the record.
Mar 24 '10 #2
slenish
283 100+
Hi NeoPa,

What do you mean by no space?? In the part where it says Shipper Referene? Should that be together? Because I have tried that as well.

The way im trying to seperate the information that is in the table is by the space that is between to two parts of information. I have read you can have the left and right split look for the space is there is not a comma or apostrophe, but I cant get it to work right.

Any examples you could show me would be greatly appreciated :D
Mar 24 '10 #3
missinglinq
3,532 Expert 2GB
Assuming that there is only the single space in the original field
Expand|Select|Wrap|Line Numbers
  1. FirstField =  Left(Me.OriginalField, InStr(Me.OriginalField, " ") - 1)
  2. SecondField = Right(Me.OriginalField, Len(Me.OriginalField) - InStr(Me.OriginalField, " "))
Linq ;0)>
Mar 25 '10 #4
slenish
283 100+
Hi Linq,

There are two spaces in the original field. I was wanting to seperate them by the second space.

the information is displayed like this

Box 1 ID12345

I want to take it and seperate it so Box 1 goes in to one column and ID12345 goes in to another. The reason I want to seperate it by the second space is because the Box # could change and become two or three numbers such as
Box 1
Box 12
Box 123

But the last part does not change as far as the amount of characters. although the ID number and the letters ID can change.
Mar 25 '10 #5
missinglinq
3,532 Expert 2GB
That's simple enough to do! You just have to replace the InStr() function with the InStrRev() function. The former searches from the beginning of a string, looking for the first instance of a search string.The latter starts at the end of the string and works backwards looking for the first instance
Expand|Select|Wrap|Line Numbers
  1. FirstField = Left(Me.OriginalField, InStrRev(Me.OriginalField, " ") - 1)
  2. SecondField = Right(Me.OriginalField, Len(Me.OriginalField) - InStrRev(Me.OriginalField, " ")).
Linq ;0)>
Mar 25 '10 #6
NeoPa
32,556 Expert Mod 16PB
I'm guessing Linq is right in that InStrRev() would indeed be the more appropriate function call for the scenario you describe. His suggestion is in VBA though, and it appears your question is query related so it may not be a perfect fit.

It's hard to make a simple suggestion though, as you don't explain what is wrong with your original code. You simply imply it doesn't do exactly as you'd expect. This is very little information to work with.

My previous comment, by the way, was a reference to the data that you are processing. Surely it would work to an extent if the data in every record contained at least one space. I was asking if there may be some records with no spaces in. I was trying to guess what your actual problem was as you hadn't explained it in your question.

I'm sure with some clearer information from you we can suggest a solution you can use from within your query. My guess is that it will be something very similar to what Linq's already suggested, but in SQL or query form.
Mar 25 '10 #7
missinglinq
3,532 Expert 2GB
You're right, NeoPa! In the Query Grid the calculated fields would be
Expand|Select|Wrap|Line Numbers
  1. FirstField: Left([OriginalField],InStrRev([OriginalField]," ")-1)
  2.  
  3. SecondField: Right([OriginalField],Len([OriginalField])-InStrRev([OriginalField]," "))
In SQL it would be
Expand|Select|Wrap|Line Numbers
  1. SELECT YourTableName.OriginalField, Left([OriginalField],InStrRev([OriginalField]," ")-1) AS FirstField, Right([OriginalField],Len([OriginalField])-InStrRev([OriginalField]," ")) AS SecondField
  2. FROM YourTableName;
Linq ;0)>
Mar 25 '10 #8
slenish
283 100+
NeoPa, and Linq

Really appreciate the help guys :D I dont know why exactly it was not working with the way I did it the first time. I took linq's last posting example(the first one not the SQL one) and re-applied it to my query and for some reason it worked perfectly this time.

The last time i just kept getting errors either asking for the parameter value, or i would get a debug error, or it would be syntax error. Dont know why i kept getting that before and this time it was fine.

Thanks so much!!
Mar 26 '10 #9
NeoPa
32,556 Expert Mod 16PB
I can see nothing in your posted code that would explain those types of errors, but with the data you describe, Linq's code is certainly what you's need to use in place of your original code.
Mar 26 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Arjen | last post by:
Hi All, What I want to is using a string as PATTERN in a split function. This makes it possible for me to change the PATTERN on one place in my script... For example: $separator = ";"; $line...
4
by: Varad | last post by:
I'm trying to break this html statement at the "<!---->" <br><a href='www.link1.com'>Link1</a><!----><br><a href='www.link2.com'>Link2</a><!----><br><a href='www.link3.com'>Link3</a><!----> ...
5
by: NewToThis | last post by:
I am trying to use the split function to bread up lines in a file I am reading from. Some lines are working just fine, but a couple of the lines don't split up the way I would have thought. ...
3
by: Reb | last post by:
Hi, I could split only by a character. How do i split by a string. How can i do something like this. e.g., somestring.Split("name"); Thanks Reb
6
by: andrewcw | last post by:
The split function takes as a parameter what I understand as array of Char. I can define the delimiter like this: string innerText = new string; char chSplit={'='};...
7
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns...
2
by: Elhanan | last post by:
hi all.. i have the following string: 200850625~01~464~^^200850625~01~464~^^200850625~01~908~^^ which i will need to turn to a mutli-dimentional string array i used result.Split(new...
5
by: sck10 | last post by:
Hello, I have a list of email addresses that I need to send email to from the website. I am trying to use the "Split" function to get all the To's and then use the uBound function for the...
1
by: John | last post by:
Hi I have written a Split function which in turn calls the standard string split function. Code is below; Function Split1(ByVal Expression As String, Optional ByVal Delimiter As String = " ",...
5
by: nagmvs | last post by:
Can anyone tell me about the usage of split function in Asp with Example ? i done one project using split function.and i have some problems regarding storing data in data base.I use there...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.