Trim Data

G

Guest

I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
A

Allen Browne

Unfortunately, address data is not standard enough for the computer to be
able to pick the street name all the time.

Looking at your data, can you identify a way that will work for most
records? For example, is it everything before the first comma? If so you
could use Instr() to locate the comma, and Left() to get the characters to
the left of that.
 
G

Guest

Do I place this in the criteria line when making the query?

KARL DEWEY said:
Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


Finger Tips said:
I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
G

Guest

If so I am getting an "Invalid Procedure Call" message when trying to run it.

Finger Tips said:
Do I place this in the criteria line when making the query?

KARL DEWEY said:
Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


Finger Tips said:
I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
G

Guest

Open your query in design view and in the Field row of the grid add this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


Finger Tips said:
Do I place this in the criteria line when making the query?

KARL DEWEY said:
Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


Finger Tips said:
I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
G

Guest

Received an "Error #" in the field when it ran the query

KARL DEWEY said:
Open your query in design view and in the Field row of the grid add this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


Finger Tips said:
Do I place this in the criteria line when making the query?

KARL DEWEY said:
Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
G

Guest

Copy and paste your SQL in a post. Open query in design view, click on menu
VIEW - SQL View, hightlight all, copy, and paste in a post.
--
KARL DEWEY
Build a little - Test a little


Finger Tips said:
Received an "Error #" in the field when it ran the query

KARL DEWEY said:
Open your query in design view and in the Field row of the grid add this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


Finger Tips said:
Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
J

John Spencer

If your field does not have a comma in it that will error, since Left
will not accept a negative number. It will accept zero and positive
numbers.

So the trick is to add the comma to the end of the field value in the
instr function call. That way the function will always return 1 when the
field is null or blank or doesn't contain a comma other than then one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger said:
Received an "Error #" in the field when it ran the query

KARL DEWEY said:
Open your query in design view and in the Field row of the grid add this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


Finger Tips said:
Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
G

Guest

Hi John, yes some of the fields only contain 2 commas and others are blank.
WHen I insert this statement though I get an "The expression you entered
contains an Invalid Syntax"

John Spencer said:
If your field does not have a comma in it that will error, since Left
will not accept a negative number. It will accept zero and positive
numbers.

So the trick is to add the comma to the end of the field value in the
instr function call. That way the function will always return 1 when the
field is null or blank or doesn't contain a comma other than then one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger said:
Received an "Error #" in the field when it ran the query

KARL DEWEY said:
Open your query in design view and in the Field row of the grid add this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
J

John Spencer

Typo on my part. Period should be a comma


LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)

Extra spaces added for clarity

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger said:
Hi John, yes some of the fields only contain 2 commas and others are blank.
WHen I insert this statement though I get an "The expression you entered
contains an Invalid Syntax"

John Spencer said:
If your field does not have a comma in it that will error, since Left
will not accept a negative number. It will accept zero and positive
numbers.

So the trick is to add the comma to the end of the field value in the
instr function call. That way the function will always return 1 when the
field is null or blank or doesn't contain a comma other than then one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger said:
Received an "Error #" in the field when it ran the query

:

Open your query in design view and in the Field row of the grid add this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
G

Guest

Still getting the #Error in the field

John Spencer said:
Typo on my part. Period should be a comma


LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)

Extra spaces added for clarity

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger said:
Hi John, yes some of the fields only contain 2 commas and others are blank.
WHen I insert this statement though I get an "The expression you entered
contains an Invalid Syntax"

John Spencer said:
If your field does not have a comma in it that will error, since Left
will not accept a negative number. It will accept zero and positive
numbers.

So the trick is to add the comma to the end of the field value in the
instr function call. That way the function will always return 1 when the
field is null or blank or doesn't contain a comma other than then one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Received an "Error #" in the field when it ran the query

:

Open your query in design view and in the Field row of the grid add this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the street
address without the city state or zip. So I guess something that will trim
everything after the first comma knowing that sometime the field is blank.
 
J

John Spencer

I tested the expression
LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)
and I don't get any error.

WHERE do you see the error? In the query itself or are you using this in a
report or form?

If in the query, please post the SQL of the query.
Please copy and post the SQL of your query.

(Possibly unneeded instructions follow)
Open the query
Select View:Sql from the Menu
Select all the text
Copy it
Paste it into the message

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Finger Tips said:
Still getting the #Error in the field

John Spencer said:
Typo on my part. Period should be a comma


LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)

Extra spaces added for clarity

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger said:
Hi John, yes some of the fields only contain 2 commas and others are
blank.
WHen I insert this statement though I get an "The expression you
entered
contains an Invalid Syntax"

:

If your field does not have a comma in it that will error, since Left
will not accept a negative number. It will accept zero and positive
numbers.

So the trick is to add the comma to the end of the field value in the
instr function call. That way the function will always return 1 when
the
field is null or blank or doesn't contain a comma other than then one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Received an "Error #" in the field when it ran the query

:

Open your query in design view and in the Field row of the grid add
this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and
need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has
information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the
street
address without the city state or zip. So I guess something that
will trim
everything after the first comma knowing that sometime the field
is blank.
 
G

Guest

here is the sql

SELECT dbo_comps11.title AS dbo_comps11_title, dbo_comps11.addr,
dbo_comps11.city, dbo_comps11.state, dbo_comps11.zip, dbo_comps11.phone,
dbo_paths.id, dbo_paths.title AS dbo_paths_title, dbo_paths.parent,
Left([dbo_comps11.addr],InStr(1,[dbo_comps11.addr] & ",",",")-1) AS Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

various scenerios of the data in the orig. field are

1400 N. Scott, Wichita Falls, TX 76306
500 East Peabody Drive, Champaign, IL 61820
Hortonville, WI 54944
3448 Steinway Street, Long Island City, NY 11101
707 Lake Boulevard, Saint Joseph, MI 49085
and Blank

The query does run and returns all other fields correctly except this one
which returns the text #Error

John Spencer said:
I tested the expression
LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)
and I don't get any error.

WHERE do you see the error? In the query itself or are you using this in a
report or form?

If in the query, please post the SQL of the query.
Please copy and post the SQL of your query.

(Possibly unneeded instructions follow)
Open the query
Select View:Sql from the Menu
Select all the text
Copy it
Paste it into the message

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Finger Tips said:
Still getting the #Error in the field

John Spencer said:
Typo on my part. Period should be a comma


LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)

Extra spaces added for clarity

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Hi John, yes some of the fields only contain 2 commas and others are
blank.
WHen I insert this statement though I get an "The expression you
entered
contains an Invalid Syntax"

:

If your field does not have a comma in it that will error, since Left
will not accept a negative number. It will accept zero and positive
numbers.

So the trick is to add the comma to the end of the field value in the
instr function call. That way the function will always return 1 when
the
field is null or blank or doesn't contain a comma other than then one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Received an "Error #" in the field when it ran the query

:

Open your query in design view and in the Field row of the grid add
this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and
need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has
information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is the
street
address without the city state or zip. So I guess something that
will trim
everything after the first comma knowing that sometime the field
is blank.
 
J

John Spencer

BAD brackets. You should surround the tablename and fieldname separately as
follows.

Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street

SELECT dbo_comps11.title AS dbo_comps11_title
, dbo_comps11.addr
, dbo_comps11.city
, dbo_comps11.state
, dbo_comps11.zip
, dbo_comps11.phone
, dbo_paths.id, dbo_paths.title AS dbo_paths_title
, dbo_paths.parent
, Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

If your field name is unique with the two tables you could use

Left([addr],InStr(1,[addr] & ",",",")-1) AS Street

And if it is unique and has no spaces or other non letter or number
characters you can even drop the brackets

Left(addr,InStr(1,addr & ",",",")-1) AS Street

Hope that takes care of the problem.


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Finger Tips said:
here is the sql

SELECT dbo_comps11.title AS dbo_comps11_title, dbo_comps11.addr,
dbo_comps11.city, dbo_comps11.state, dbo_comps11.zip, dbo_comps11.phone,
dbo_paths.id, dbo_paths.title AS dbo_paths_title, dbo_paths.parent,
Left([dbo_comps11.addr],InStr(1,[dbo_comps11.addr] & ",",",")-1) AS Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

various scenerios of the data in the orig. field are

1400 N. Scott, Wichita Falls, TX 76306
500 East Peabody Drive, Champaign, IL 61820
Hortonville, WI 54944
3448 Steinway Street, Long Island City, NY 11101
707 Lake Boulevard, Saint Joseph, MI 49085
and Blank

The query does run and returns all other fields correctly except this one
which returns the text #Error

John Spencer said:
I tested the expression
LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)
and I don't get any error.

WHERE do you see the error? In the query itself or are you using this in
a
report or form?

If in the query, please post the SQL of the query.
Please copy and post the SQL of your query.

(Possibly unneeded instructions follow)
Open the query
Select View:Sql from the Menu
Select all the text
Copy it
Paste it into the message

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Finger Tips said:
Still getting the #Error in the field

:

Typo on my part. Period should be a comma


LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)

Extra spaces added for clarity

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Hi John, yes some of the fields only contain 2 commas and others are
blank.
WHen I insert this statement though I get an "The expression you
entered
contains an Invalid Syntax"

:

If your field does not have a comma in it that will error, since
Left
will not accept a negative number. It will accept zero and
positive
numbers.

So the trick is to add the comma to the end of the field value in
the
instr function call. That way the function will always return 1
when
the
field is null or blank or doesn't contain a comma other than then
one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Received an "Error #" in the field when it ran the query

:

Open your query in design view and in the Field row of the grid
add
this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and
need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has
information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is
the
street
address without the city state or zip. So I guess something
that
will trim
everything after the first comma knowing that sometime the
field
is blank.
 
G

Guest

Still getting the same #Error

John Spencer said:
BAD brackets. You should surround the tablename and fieldname separately as
follows.

Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street

SELECT dbo_comps11.title AS dbo_comps11_title
, dbo_comps11.addr
, dbo_comps11.city
, dbo_comps11.state
, dbo_comps11.zip
, dbo_comps11.phone
, dbo_paths.id, dbo_paths.title AS dbo_paths_title
, dbo_paths.parent
, Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

If your field name is unique with the two tables you could use

Left([addr],InStr(1,[addr] & ",",",")-1) AS Street

And if it is unique and has no spaces or other non letter or number
characters you can even drop the brackets

Left(addr,InStr(1,addr & ",",",")-1) AS Street

Hope that takes care of the problem.


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Finger Tips said:
here is the sql

SELECT dbo_comps11.title AS dbo_comps11_title, dbo_comps11.addr,
dbo_comps11.city, dbo_comps11.state, dbo_comps11.zip, dbo_comps11.phone,
dbo_paths.id, dbo_paths.title AS dbo_paths_title, dbo_paths.parent,
Left([dbo_comps11.addr],InStr(1,[dbo_comps11.addr] & ",",",")-1) AS Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

various scenerios of the data in the orig. field are

1400 N. Scott, Wichita Falls, TX 76306
500 East Peabody Drive, Champaign, IL 61820
Hortonville, WI 54944
3448 Steinway Street, Long Island City, NY 11101
707 Lake Boulevard, Saint Joseph, MI 49085
and Blank

The query does run and returns all other fields correctly except this one
which returns the text #Error

John Spencer said:
I tested the expression
LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)
and I don't get any error.

WHERE do you see the error? In the query itself or are you using this in
a
report or form?

If in the query, please post the SQL of the query.
Please copy and post the SQL of your query.

(Possibly unneeded instructions follow)
Open the query
Select View:Sql from the Menu
Select all the text
Copy it
Paste it into the message

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Still getting the #Error in the field

:

Typo on my part. Period should be a comma


LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)

Extra spaces added for clarity

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Hi John, yes some of the fields only contain 2 commas and others are
blank.
WHen I insert this statement though I get an "The expression you
entered
contains an Invalid Syntax"

:

If your field does not have a comma in it that will error, since
Left
will not accept a negative number. It will accept zero and
positive
numbers.

So the trick is to add the comma to the end of the field value in
the
instr function call. That way the function will always return 1
when
the
field is null or blank or doesn't contain a comma other than then
one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Received an "Error #" in the field when it ran the query

:

Open your query in design view and in the Field row of the grid
add
this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and
need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has
information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is
the
street
address without the city state or zip. So I guess something
that
will trim
everything after the first comma knowing that sometime the
field
is blank.
 
G

Guest

Ok John, I found some other items in the field that may be effecting the
result. Here are some of the data as it appears in the addr field. In these
cases I would just want the field returned blank.

# 99.5, Key West, FL 33040
(401)-996-1670, Riverside, RI 02915
.., Bridgeton, NJ 08302
.., Huntingdon Valley, PA 19006
.., Jacksonville, FL 32202
.., Lynnfield, MA 01940
.., Phoenixville, PA 19460
.., Tampa, FL 33612
.., Tampa, FL 33612
.., Tampa, FL 33612
.., Williamsport, PA 17702
...., Anderson, SC 29621
...., Greenville, SC 29601
/NP/, Redmond, WA 98053
?, Colchester, VT 05446
_, Boston, MA 02284


Finger Tips said:
Still getting the same #Error

John Spencer said:
BAD brackets. You should surround the tablename and fieldname separately as
follows.

Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street

SELECT dbo_comps11.title AS dbo_comps11_title
, dbo_comps11.addr
, dbo_comps11.city
, dbo_comps11.state
, dbo_comps11.zip
, dbo_comps11.phone
, dbo_paths.id, dbo_paths.title AS dbo_paths_title
, dbo_paths.parent
, Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

If your field name is unique with the two tables you could use

Left([addr],InStr(1,[addr] & ",",",")-1) AS Street

And if it is unique and has no spaces or other non letter or number
characters you can even drop the brackets

Left(addr,InStr(1,addr & ",",",")-1) AS Street

Hope that takes care of the problem.


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Finger Tips said:
here is the sql

SELECT dbo_comps11.title AS dbo_comps11_title, dbo_comps11.addr,
dbo_comps11.city, dbo_comps11.state, dbo_comps11.zip, dbo_comps11.phone,
dbo_paths.id, dbo_paths.title AS dbo_paths_title, dbo_paths.parent,
Left([dbo_comps11.addr],InStr(1,[dbo_comps11.addr] & ",",",")-1) AS Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

various scenerios of the data in the orig. field are

1400 N. Scott, Wichita Falls, TX 76306
500 East Peabody Drive, Champaign, IL 61820
Hortonville, WI 54944
3448 Steinway Street, Long Island City, NY 11101
707 Lake Boulevard, Saint Joseph, MI 49085
and Blank

The query does run and returns all other fields correctly except this one
which returns the text #Error

:

I tested the expression
LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)
and I don't get any error.

WHERE do you see the error? In the query itself or are you using this in
a
report or form?

If in the query, please post the SQL of the query.
Please copy and post the SQL of your query.

(Possibly unneeded instructions follow)
Open the query
Select View:Sql from the Menu
Select all the text
Copy it
Paste it into the message

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Still getting the #Error in the field

:

Typo on my part. Period should be a comma


LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)

Extra spaces added for clarity

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Hi John, yes some of the fields only contain 2 commas and others are
blank.
WHen I insert this statement though I get an "The expression you
entered
contains an Invalid Syntax"

:

If your field does not have a comma in it that will error, since
Left
will not accept a negative number. It will accept zero and
positive
numbers.

So the trick is to add the comma to the end of the field value in
the
instr function call. That way the function will always return 1
when
the
field is null or blank or doesn't contain a comma other than then
one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Received an "Error #" in the field when it ran the query

:

Open your query in design view and in the Field row of the grid
add
this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and
need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has
information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is
the
street
address without the city state or zip. So I guess something
that
will trim
everything after the first comma knowing that sometime the
field
is blank.
 
J

John Spencer

At this point it is time to apply someone's brain and clean up the data.
This is getting pretty complicated.

While I could develop a VBA function that would clean out some of this
data, it would be more time than I am willing to donate.

Sorry.

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger said:
Ok John, I found some other items in the field that may be effecting the
result. Here are some of the data as it appears in the addr field. In these
cases I would just want the field returned blank.

# 99.5, Key West, FL 33040
(401)-996-1670, Riverside, RI 02915
., Bridgeton, NJ 08302
., Huntingdon Valley, PA 19006
., Jacksonville, FL 32202
., Lynnfield, MA 01940
., Phoenixville, PA 19460
., Tampa, FL 33612
., Tampa, FL 33612
., Tampa, FL 33612
., Williamsport, PA 17702
..., Anderson, SC 29621
..., Greenville, SC 29601
/NP/, Redmond, WA 98053
?, Colchester, VT 05446
_, Boston, MA 02284


Finger Tips said:
Still getting the same #Error

John Spencer said:
BAD brackets. You should surround the tablename and fieldname separately as
follows.

Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street

SELECT dbo_comps11.title AS dbo_comps11_title
, dbo_comps11.addr
, dbo_comps11.city
, dbo_comps11.state
, dbo_comps11.zip
, dbo_comps11.phone
, dbo_paths.id, dbo_paths.title AS dbo_paths_title
, dbo_paths.parent
, Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

If your field name is unique with the two tables you could use

Left([addr],InStr(1,[addr] & ",",",")-1) AS Street

And if it is unique and has no spaces or other non letter or number
characters you can even drop the brackets

Left(addr,InStr(1,addr & ",",",")-1) AS Street

Hope that takes care of the problem.


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

here is the sql

SELECT dbo_comps11.title AS dbo_comps11_title, dbo_comps11.addr,
dbo_comps11.city, dbo_comps11.state, dbo_comps11.zip, dbo_comps11.phone,
dbo_paths.id, dbo_paths.title AS dbo_paths_title, dbo_paths.parent,
Left([dbo_comps11.addr],InStr(1,[dbo_comps11.addr] & ",",",")-1) AS Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

various scenerios of the data in the orig. field are

1400 N. Scott, Wichita Falls, TX 76306
500 East Peabody Drive, Champaign, IL 61820
Hortonville, WI 54944
3448 Steinway Street, Long Island City, NY 11101
707 Lake Boulevard, Saint Joseph, MI 49085
and Blank

The query does run and returns all other fields correctly except this one
which returns the text #Error

:

I tested the expression
LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)
and I don't get any error.

WHERE do you see the error? In the query itself or are you using this in
a
report or form?

If in the query, please post the SQL of the query.
Please copy and post the SQL of your query.

(Possibly unneeded instructions follow)
Open the query
Select View:Sql from the Menu
Select all the text
Copy it
Paste it into the message

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Still getting the #Error in the field

:

Typo on my part. Period should be a comma


LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)

Extra spaces added for clarity

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Hi John, yes some of the fields only contain 2 commas and others are
blank.
WHen I insert this statement though I get an "The expression you
entered
contains an Invalid Syntax"

:

If your field does not have a comma in it that will error, since
Left
will not accept a negative number. It will accept zero and
positive
numbers.

So the trick is to add the comma to the end of the field value in
the
instr function call. That way the function will always return 1
when
the
field is null or blank or doesn't contain a comma other than then
one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Received an "Error #" in the field when it ran the query

:

Open your query in design view and in the Field row of the grid
add
this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and
need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has
information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is
the
street
address without the city state or zip. So I guess something
that
will trim
everything after the first comma knowing that sometime the
field
is blank.
 
G

Guest

John, so there is no trim expression that will just leave everything to the
left of the first , no matter what is and eliminate everything to the right?

John Spencer said:
At this point it is time to apply someone's brain and clean up the data.
This is getting pretty complicated.

While I could develop a VBA function that would clean out some of this
data, it would be more time than I am willing to donate.

Sorry.

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger said:
Ok John, I found some other items in the field that may be effecting the
result. Here are some of the data as it appears in the addr field. In these
cases I would just want the field returned blank.

# 99.5, Key West, FL 33040
(401)-996-1670, Riverside, RI 02915
., Bridgeton, NJ 08302
., Huntingdon Valley, PA 19006
., Jacksonville, FL 32202
., Lynnfield, MA 01940
., Phoenixville, PA 19460
., Tampa, FL 33612
., Tampa, FL 33612
., Tampa, FL 33612
., Williamsport, PA 17702
..., Anderson, SC 29621
..., Greenville, SC 29601
/NP/, Redmond, WA 98053
?, Colchester, VT 05446
_, Boston, MA 02284


Finger Tips said:
Still getting the same #Error

:

BAD brackets. You should surround the tablename and fieldname separately as
follows.

Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street

SELECT dbo_comps11.title AS dbo_comps11_title
, dbo_comps11.addr
, dbo_comps11.city
, dbo_comps11.state
, dbo_comps11.zip
, dbo_comps11.phone
, dbo_paths.id, dbo_paths.title AS dbo_paths_title
, dbo_paths.parent
, Left([dbo_comps11].[addr],InStr(1,[dbo_comps11].[addr] & ",",",")-1) AS
Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

If your field name is unique with the two tables you could use

Left([addr],InStr(1,[addr] & ",",",")-1) AS Street

And if it is unique and has no spaces or other non letter or number
characters you can even drop the brackets

Left(addr,InStr(1,addr & ",",",")-1) AS Street

Hope that takes care of the problem.


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

here is the sql

SELECT dbo_comps11.title AS dbo_comps11_title, dbo_comps11.addr,
dbo_comps11.city, dbo_comps11.state, dbo_comps11.zip, dbo_comps11.phone,
dbo_paths.id, dbo_paths.title AS dbo_paths_title, dbo_paths.parent,
Left([dbo_comps11.addr],InStr(1,[dbo_comps11.addr] & ",",",")-1) AS Street
FROM dbo_paths INNER JOIN ((dbo_comps11 INNER JOIN dbo_links ON
dbo_comps11.id = dbo_links.id) INNER JOIN dbo_dirs ON dbo_links.parent =
dbo_dirs.id) ON dbo_paths.id = dbo_dirs.parent
WHERE (((dbo_paths.parent)=60003));

various scenerios of the data in the orig. field are

1400 N. Scott, Wichita Falls, TX 76306
500 East Peabody Drive, Champaign, IL 61820
Hortonville, WI 54944
3448 Steinway Street, Long Island City, NY 11101
707 Lake Boulevard, Saint Joseph, MI 49085
and Blank

The query does run and returns all other fields correctly except this one
which returns the text #Error

:

I tested the expression
LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)
and I don't get any error.

WHERE do you see the error? In the query itself or are you using this in
a
report or form?

If in the query, please post the SQL of the query.
Please copy and post the SQL of your query.

(Possibly unneeded instructions follow)
Open the query
Select View:Sql from the Menu
Select all the text
Copy it
Paste it into the message

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Still getting the #Error in the field

:

Typo on my part. Period should be a comma


LEFT([YourField] , Instr(1 , [YourField] & "," , ",")-1)

Extra spaces added for clarity

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Hi John, yes some of the fields only contain 2 commas and others are
blank.
WHen I insert this statement though I get an "The expression you
entered
contains an Invalid Syntax"

:

If your field does not have a comma in it that will error, since
Left
will not accept a negative number. It will accept zero and
positive
numbers.

So the trick is to add the comma to the end of the field value in
the
instr function call. That way the function will always return 1
when
the
field is null or blank or doesn't contain a comma other than then
one
you have temporarily added.


LEFT([YourField], Instr(1.[YourField] & ",",",")-1)



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Finger Tips wrote:
Received an "Error #" in the field when it ran the query

:

Open your query in design view and in the Field row of the grid
add
this in a
blank.
Street: Left([YourFieldName], InStr([YourFieldName], ",")-1)

--
KARL DEWEY
Build a little - Test a little


:

Do I place this in the criteria line when making the query?

:

Try this --
Left([YourFieldName], InStr([YourFieldName], ",")-1)
--
KARL DEWEY
Build a little - Test a little


:

I know this may be answered somewhere but I am new at this and
need very
specific steps. Screen shots also help.

I am running a query. In one of the fields "addr: it has
information like
this example.

236 West Rezanof Drive, Kodiak, AK 99615
or
Kodiak, AK 99615

or

Some may be blank. The only thing I want from this field is
the
street
address without the city state or zip. So I guess something
that
will trim
everything after the first comma knowing that sometime the
field
is blank.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Trim Statement 1
trim 3
Making four queries into one 1
left trim 9
trim in query 6
Error message in query? 2
Help writing a formula 3
remove text 21

Top