473,426 Members | 1,615 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,426 software developers and data experts.

Forumla to get part of the string

Hi,
Im trying to write a query which takes part of the string for example:

peter_Poland
michael_Germany

I wish to get output:
peter
michael

regards
Piotr

Nov 25 '05 #1
5 4219
Type somehing like this into the Field row in your query:
Left([Field1], Instr([Field1], "_") -1)
replacing Field1 with the name of your field.

To avoid the error for fields that have no underscore, enter this into the
Criteria row as well
Like "?*_*"

(That expression almost looks like a piece of ASCII-art.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Piotr" <ho***@wp.pl> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi,
Im trying to write a query which takes part of the string for example:

peter_Poland
michael_Germany

I wish to get output:
peter
michael

regards
Piotr

Nov 25 '05 #2
On 24 Nov 2005 23:55:50 -0800, "Piotr" <ho***@wp.pl> wrote:
Hi,
Im trying to write a query which takes part of the string for example:

peter_Poland
michael_Germany

I wish to get output:
peter
michael

regards
Piotr


If strName is the holder for the above names, then using:

mid(strName,1,instr(1,strName,"_")-1)

will give you the first name.

Note that this will only work as long as the underscore character
actually exists in the strName holder. If it doesn't, the function
will give you an error. A way around it, if that is a possibility, is
to do:

Iif(instr(1,strName,"_")=0,"",mid(strName,1,instr( 1,strName,"_")-1))

but this isn't needed if your data always has an underscore in it.

mike
Nov 25 '05 #3
Piotr wrote:
Hi,
Im trying to write a query which takes part of the string for example:

peter_Poland
michael_Germany

I wish to get output:
peter
michael

regards
Piotr


IOW you want the part of the column before the "_" ?

Left(fieldname,instr(1,fieldname,"_")-1)
Nov 25 '05 #4
Im keep on trying do this query and I still get statement error ?

Exam: Left([net_hal],instr(1,[net_hal],"_")-1)

What can be wrong ?

Im trying tp use InStr alone and doesnt work also ?
Could be no such function in my access ?

Nov 25 '05 #5
wow thank its working I had to put ; instead of ,

Nov 25 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matthias Ludwig | last post by:
I'm trying to create a directory on the web server with a vb.net code: .... Dim dirName As String = "w:\filepath\images" If Not Directory.Exists(dirName) Then...
1
by: Alex | last post by:
Hello, in my company, we have a diagnostic tool for hardware. Depending on the hardware projcet, a different project configuration is needed. The configuration file is written in XML and...
5
by: ad | last post by:
I have a string like string myString="dog,cat,dog,tiger" I want to delete the duplication part, and make myString to "dog,cat,tiger" How can I do that?
1
by: SMG | last post by:
Hi All, My Send mail system was working very fine, today suddenly it started giving me following error. Can any one suggest why this is happening so. I am using system.Web.Mail "The requested...
12
by: Ima Loozer | last post by:
OK folks here is what I need help with. Lets assume I have a text field that will contain AlphaNumeric data. There is no set pattern to the field such that any given character can be either alpha...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
0
by: bill | last post by:
IMAP_FETCHBODY requires the "part number" to fetch. Can anyone point me at how the part numbers are derrived. for example, here is the formatted parts array from a message: Parts: array(2) {...
3
by: wassimdaccache | last post by:
I'm using this code to search a value on a continuous form it is working properly Am I able to write for example part of the string Dim strCriteria As String Dim rst As DAO.Recordset ...
4
by: Andrew Poulos | last post by:
I have a string that looks like this "cmi.interactions.fred.id" I need to test that: - the first part of the string is "cmi.interactions." (case sensitive). - the last part of the string is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
1
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.