Query to return text to the left of a space in string (1 Viewer)

peffw

New member
Local time
Today, 03:09
Joined
Jan 12, 2012
Messages
3
Hi,

Has anyone got a suggestion as to how I can run an update query which populates a new field with the the text to the left of the first space in a string? I'm trying to create a first name field from data where the first and middle name are in the same field.

Thanks

GEOFF
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:09
Joined
Aug 30, 2003
Messages
36,127
Try the Left() function using the InStr() function to find the position of the space.
 

peffw

New member
Local time
Today, 03:09
Joined
Jan 12, 2012
Messages
3
Thanks Paul. I looked up InStr on Access help (I'm not a programmer) and tried to use an example they had in a query by substituting field names as follows

Expr1:Left([forenames],(InStr(1,[forenames],"."))-1)

The query returned an error. Any thoughts on what I'm doing wrong?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:09
Joined
Aug 30, 2003
Messages
36,127
I thought you were looking for a space? That's looking for a period, and will probably error if there is none.
 

peffw

New member
Local time
Today, 03:09
Joined
Jan 12, 2012
Messages
3
Sorry I was. The joys of cut and paste! I've substituted the full stop with a space and it works! Thanks for your help.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:09
Joined
Aug 30, 2003
Messages
36,127
No problem, and welcome to the site. As illustrated by the problem you had, this will likely error if there's no space in the field. If that's a possibility, we'll have to tweak it.
 

Armedinstructor

New member
Local time
Yesterday, 21:09
Joined
Feb 9, 2023
Messages
1
I am experiencing the problem you have described above about there not containing a space in some cases. Can you help?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 03:09
Joined
Feb 19, 2013
Messages
16,629
you have hijacked an 11 year old thread with effectively a different question.

Please start a new thread with your question and provide some example data to illustrate what you have and what outcome you require
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:09
Joined
Feb 19, 2002
Messages
43,346
Otherwise, we're happy you found us and we're looking forward to helping:) But we will need more information when you post your new question. Post some sample data and the expression you are using so we know what problem you are trying to solve.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:09
Joined
Aug 30, 2003
Messages
36,127
I am experiencing the problem you have described above about there not containing a space in some cases. Can you help?

Test for it with an IIf, along the lines of

IIf(InStr(1,[forenames], " ") = 0,"", Left([forenames],(InStr(1,[forenames]," "))-1))
 

Users who are viewing this thread

Top Bottom