Hi everyone,
Im trying to take one column (in my query) and split the data in four different columns. so far i have the first part of the information and the last part of the information to split fine. I just cant get the middle part to split right.
Here is what im trying to split.
IDDW - Livermore, CA 94550
Every record in the table is the same so i want it to split at the - then at the first , and then at the space so you would have four fields that would say
Column1.Column2....Column3....Column4
IDDW.... Livermore.......CA ..........94550
Here is what i have so far -
Exp1: Left([Shipper Reference#],InStrRev([Shipper Reference#]," - ")-1)
-
Exp2: Right([Shipper Reference#],Len([Shipper Reference#])-InStrRev([Shipper Reference#]," "))
I added it to to more columns and keep trying to change these in hopes to get something but im having no luck so far.
Thanks for the help.
5 21422
In situations like this, I always find it helpful to write a quick function to do the work for me. That way you don't have to squeeze everything on to a single line. - Function SplitRef(SplitString As String, Section As Integer)
-
Select Case Section
-
Case 1:
-
StartPos = 1
-
EndPos = InStr(SplitString, "-") - 2
-
Case 2:
-
StartPos = InStr(SplitString, "-") + 2
-
EndPos = InStr(SplitString, ",") - 1
-
Case 3:
-
StartPos = InStr(SplitString, ",") + 2
-
EndPos = InStrRev(SplitString, " ") - 1
-
Case 4:
-
StartPos = InStrRev(SplitString, " ") + 1
-
EndPos = Len(SplitString)
-
End Select
-
SplitRef = Mid(SplitString, StartPos, EndPos - StartPos + 1)
-
End Function
1st: - ?SplitRef("IDDW - Livermore, CA 94550", 1)
-
IDDW
-
2nd: - ?SplitRef("IDDW - Livermore, CA 94550", 2)
-
Livermore
-
3rd: - ?SplitRef("IDDW - Livermore, CA 94550", 3)
-
CA
4th: - ?SplitRef("IDDW - Livermore, CA 94550", 4)
-
94550
This works with the example given, but could benefit from some added error checking.
In response to gershwyns excellent posting ... (if you are not too familiar with the mechanics of how to implement this function) once you have created the function in a VBA module you call it via the query grid and the SQL for the query will look like the below where the reference YourTableName= the actual name of your table.
Gershwyns post demonstrates how to create the function. You can then simply call it as you would any other inbuilt Access function. -
SELECT SplitRef([Shipper Reference],1) AS Column1,
-
SplitRef([Shipper Reference],2) AS Column2,
-
SplitRef([Shipper Reference],3) AS Column3,
-
SplitRef([Shipper Reference],4) AS Column4
-
FROM YourTableName;
Wow really appreciate the help from both of you.
Well i got it to work but there was a debug error with this line -
SplitRef = Mid(SplitString, StartPos, EndPos - StartPos + 1)
-
any idea why?
Thanks again
@slenish
Is your data consistent? my guess is that it is not. The function will not deal with all eventualities of inconsistent data appearing in your text string. The function itself is explicit for your given example pattern.
This is why error checking within the function for zero length strings nulls and other anomolies passed in is important where it does not follow the pattern you describe.
There are many purpose built string manipulation functions available LEFT,RIGHT, INSTR, MID, SPLIT and so on, but all rely on specifics and arguments in order to delimit and parse data into separate entities.
Have a look at your data first then understand the concept of the function as contributed particularly the startpos and endpos variables, These variables are examining the position of a single character within the string at a given point in your data string and adding or substracting numeric values in order to set the position. If the values do not exist in the data then the return value for the INSTR function will be 0 therefore subtracting -1 would not make sense. 'What if' scenarios that undermine your function have to be neutralised and can be done once any problems your data may pose has been considered.
NeoPa 32,556
Expert Mod 16PB
any idea why?
I suspect one of the values in that line reflects data that doesn't match the expected format.
Did you know that for most simple variables (objects can be more complicated but their default properties often show up ok) you can hover over them with the mouse when code execution is paused and the value will display in a tool-tip type bubble (See Debugging in VBA). If you examine the data you will understand exactly what's wrong (at least if not, you can tell us the values & we'll explain).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: lion |
last post by:
my Problem:
a query string passed into a html page doesn't display correctly on a
mac
I am just using html and javascript (no ASP, PHP or server side
scripting)
This is the query string:...
|
by: Dr. Oz |
last post by:
Hi,
I am trying to read in a query string from one page and build a link to
another page based on the query string.
Here's the code I am using to read in the query string:
<script...
|
by: Tom |
last post by:
I've used heredocs for single SQL statements without a problem. Also,
I've tried this using the SQL form on PhpMyAdmin and it works so I
conclude it should work in PHP.
Problem: getting syntax...
|
by: Roland Hall |
last post by:
In Access you use "*" + + "*", + can be replaced with &
Calling a parameterized query in Access requires % be used in place of *,
however, all that I have read show dynamic SQL passed to Access:
...
|
by: Skip |
last post by:
OK, I'm a novice in JS but have lots of coding experience. I am
trying to accomplish something that would seem somewhat simple - BUT
IT'S NOT.
I have a basic window that calls another window...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Uploading files from a local computer to a remote web server has many useful purposes, the most...
|
by: dougans |
last post by:
Hey there,
Hope someone can help me, completely stuck with immigrating from php4 to OOP based php5.
==
index.php
--
include(database.inc.php);
|
by: shivendravikramsingh |
last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
|
by: I Hate My Computer |
last post by:
I am using frames on a website. The title link on the title page adds a query string. The link goes to a page with two rows the second has two columns. I want the right column to be changed depending...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |