How do I do this...

N

NickTheBatMan

I have 3 columns.
Name - Home - Mobile

Some of the Home cells are not filled but all of the Name and Mobile
ones are

What I want to do is to sense if the Home is occupied then to copy the
Name combine them and add them to the list...

I will eventually be changing the Home column to CatNr and only want a
Name and TelNr

Don't want much do I !

The reason for all this is that I'm using someone else's database but
importing from Word documents !
Not ideal but... that's the way it is !

TIA

Nick
 
S

sweet_dreams

Hi,

If you want to find out if there is value in specified column you can
use IS NOT NULL:

SELECT table1.name, table1.home, table1.mobile
FROM table1
WHERE (((table1.home) Is Not Null));

above query will return all records which don't have home field
filled.

then if you want to combine home and name you simply have to use
concatenation operator like "+" or "&". your query will look like
this:

SELECT [name]+" "+[home] AS name_home
FROM table1
WHERE (((table1.home) Is Not Null));

hope that helps,
Sebastian
 
S

sweet_dreams

Hi,

First of all use IS NOT NULL to elimitate records which don't have
value in home field. Then use concatentaion operator to joim value
from name and home fields:

SELECT [name]+" "+[home] AS name_home
FROM table1
WHERE (((table1.home) Is Not Null));

Hope this helps.

Regards,
Sebastian
 
N

NickTheBatMan

Hi,

First of all use IS NOT NULL to elimitate records which don't have
value in home field. Then use concatentaion operator to joim value
from name and home fields:

SELECT [name]+" "+[home] AS name_home
FROM table1
WHERE (((table1.home) Is Not Null));

Hope this helps.

Regards,
Sebastian

Sebastian,

Thank you for that but I am a total novice and am really struggling...

I've started a new query from a table and have pasted the above 3
lines into the Field.

I have changed table1 to the apropriate name and capitalised Name &
Home as they are in the table fields but am being told 'The syntax of
the subquery in this expression is incorrect' and that I should 'check
the subquery's syntax and enclose the subquery in parentheses'

I really don't know how this works, and am indebted to you for trying
to help :)

Nick
 
T

Tom Wickerath

Hi Nick,

To use Sebastian's suggestion, change to SQL View first. Create a new query.
Dismiss the Add Tables dialog without adding any tables. Then click on View |
SQL View. You should see the SQL (Structured Query Language) keyword SELECT
selected. Replace this with the SQL statement that Sebastian volunteered,
making the appropriate changes in the table and field names. You can run the
query directly from SQL View, or switch back to the more familiar design
view, by clicking on View | Design View.
...and capitalised Name & Home as they are in the table fields...

Access, and more specifically the JET database engine, is not case
sensitive. However, I do encourage you to avoid the use of any reserved words
for things that you assign a name to within Access. Name is considered a
reserved word. Access MVP Allen Browne maintains an extensive listing of
reserved words here:

Problem names and reserved words in Access
http://allenbrowne.com/AppIssueBadWord.html

He also has a free utility that you can download to scan your Access
applications for the use of reserved words in table and field names.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
P

Pete D.

To help folks help you switch your query to SQL view, copy it and paste in
your next post.
NickTheBatMan said:
Hi,

First of all use IS NOT NULL to elimitate records which don't have
value in home field. Then use concatentaion operator to joim value
from name and home fields:

SELECT [name]+" "+[home] AS name_home
FROM table1
WHERE (((table1.home) Is Not Null));

Hope this helps.

Regards,
Sebastian

Sebastian,

Thank you for that but I am a total novice and am really struggling...

I've started a new query from a table and have pasted the above 3
lines into the Field.

I have changed table1 to the apropriate name and capitalised Name &
Home as they are in the table fields but am being told 'The syntax of
the subquery in this expression is incorrect' and that I should 'check
the subquery's syntax and enclose the subquery in parentheses'

I really don't know how this works, and am indebted to you for trying
to help :)

Nick
 
N

NickTheBatMan

Hi Nick,

To use Sebastian's suggestion, change to SQL View first. Create a new query.
Dismiss the Add Tables dialog without adding any tables. Then click on View |
SQL View. You should see the SQL (Structured Query Language) keyword SELECT
selected. Replace this with the SQL statement that Sebastian volunteered,
making the appropriate changes in the table and field names. You can run the
query directly from SQL View, or switch back to the more familiar design
view, by clicking on View | Design View.


Access, and more specifically the JET database engine, is not case
sensitive. However, I do encourage you to avoid the use of any reserved words
for things that you assign a name to within Access. Name is considered a
reserved word. Access MVP Allen Browne maintains an extensive listing of
reserved words here:

     Problem names and reserved words in Access
     http://allenbrowne.com/AppIssueBadWord.html

He also has a free utility that you can download to scan your Access
applications for the use of reserved words in table and field names.

Tom Wickerath
Microsoft Access MVPhttp://www.accessmvp.com/TWickerath/http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________










- Show quoted text -

Very many thanks Tom - and Pete below - that's made it very simple for
me and worked :)

The OTHER problem I had was that I'd named the table as 2 separate
words and as I've found Access doesn't like that either... majorly
virticle learning curve here, many thanks for all your assistance...

Just a couple more things - if you're willing to assist after all
this...? :)

The way Sebastian has done it for me it puts all the names and numbers
in 1 column, I was hoping that it may put it into 2 separate ones...

I've also got my work cut out taking all the spaces out of the numbers
that have been entered to aid readability, it would be wonderful if it
was easy to remove them in one simple operation... It varies how
they've been done, 0123 456 7890 or 012345 67890 or 01234 567 890 I'm
sure you follow...

VMTIA all

Nick
 
T

Tom Wickerath

Hi Nick,
The OTHER problem I had was that I'd named the table as 2 separate
words and as I've found Access doesn't like that either...

Well, Access (and the JET database engine) can deal with this fine, as long
as you always remember to surround any references to objects with spaces in
their names with square brackets. For example, [Order Details]. The sample
Northwind.mdb database is just full of bad naming examples that violate
Microsoft's own guidelines!

majorly verticle learning curve here, many thanks for all your assistance...

You're welcome. May I suggest that you download a copy of a zipped Word
document that I call "Access Links.doc"? I plan on reposting this document as
a better organized web page sometime in the future, but for now it is a Word
document. I recommend that you pay really close attention to the first (3)
pages, and also to the two links shown in red font on page 4. Just skim the
rest of the document every now and then, so that you have a general idea of
the types of information that it includes. But pay really good attention to
the first three pages in particular. You can download a zipped copy from here:

http://www.accessmvp.com/TWickerath/

Also, an excellent resource is Access MVP Crystal's Access Basics tutorials,
available here:
http://www.accessmvp.com/Strive4Peace/Index.htm

The way Sebastian has done it for me it puts all the names and numbers
in 1 column, I was hoping that it may put it into 2 separate ones...

You can do this, however, a combo box will only display the first column of
width greater than zero when it is not dropped down. You will only see the
second column when you click on the combo box to open it up. His first
version should do the trick:

SELECT table1.name, table1.home, table1.mobile
FROM table1
WHERE (((table1.home) Is Not Null));

Notice that the concatenation operator (+ sign) has been replaced by a
comma. Make sure that the column count matches (3 in the above case), and
that the column widths are set appropriately.

I've also got my work cut out taking all the spaces out of the numbers
that have been entered to aid readability,

I'm not understanding you on this issue. Spaces in data values should not be
a problem. The advice to avoid spaces applies to things that you assign a
name to within Access (ie. fields, tables, queries, forms, reports, macros,
modules, controls on forms and reports, variable names, etc.). It does not
apply to spaces that are a part of the data stored in the tables.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
N

NickTheBatMan

Hi Nick,
The OTHER problem I had was that I'd named the table as 2 separate
words and as I've found Access doesn't like that either...

Well, Access (and the JET database engine) can deal with this fine, as long
as you always remember to surround any references to objects with spaces in
their names with square brackets. For example, [Order Details]. The sample
Northwind.mdb database is just full of bad naming examples that violate
Microsoft's own guidelines!

Ah ha, thank you for that, another thing learnt :) Good to see that
MS provide good examples as usual ;)
You're welcome. May I suggest that you download a copy of a zipped Word
document that I call "Access Links.doc"? I plan on reposting this documentas
a better organized web page sometime in the future, but for now it is a Word
document. I recommend that you pay really close attention to the first (3)
pages, and also to the two links shown in red font on page 4. Just skim the
rest of the document every now and then, so that you have a general idea of
the types of information that it includes. But pay really good attention to
the first three pages in particular. You can download a zipped copy from here:

     http://www.accessmvp.com/TWickerath/

Thank you again :)
I'm at work and for some reason they won't let me download it - shall
do so at home tonight...
Also, an excellent resource is Access MVP Crystal's Access Basics tutorials,
available here:
     http://www.accessmvp.com/Strive4Peace/Index.htm

Many thanks for this too, I shall see what I can work from that too...
You can do this, however, a combo box will only display the first column of
width greater than zero when it is not dropped down. You will only see the
second column when you click on the combo box to open it up. His first
version should do the trick:

SELECT table1.name, table1.home, table1.mobile
FROM table1
WHERE (((table1.home) Is Not Null));

Notice that the concatenation operator (+ sign) has been replaced by a
comma. Make sure that the column count matches (3 in the above case), and
that the column widths are set appropriately.

I'm not sure what you mean by this talking about Combo Box but am sure
I'll learn - using the above I see that Access creates columns where a
comma is inserted into the script, I can now create new tables from
that and get things going as I want...
I'm not understanding you on this issue. Spaces in data values should not be
a problem. The advice to avoid spaces applies to things that you assign a
name to within Access (ie. fields, tables, queries, forms, reports, macros,
modules, controls on forms and reports, variable names, etc.). It does not
apply to spaces that are a part of the data stored in the tables.

Ah, so Access will see 01234 567 890 or 01 234 567 890 in a field as
01234567890 ? If so I don't need to go through the painful process of
removing several thousand spaces...

As I think I said, I'm working on a db that has already been produced
in a certain format and am trying to import loads of data from
documents and spreadsheets that have been produced in other formats by
other people ! :eek:

Many thanks again Tom :)
If I need any more assistance I'll be back...

Nick
 
T

Tom Wickerath

Hi Nick,
I'm not sure what you mean by this talking about Combo Box...

Somehow I got the idea that you were using your SQL statement (ie. query) as
the Rowsource for a combo box. Apparently not, so you can disregard that part
of my previous answer.

Ah, so Access will see 01234 567 890 or 01 234 567 890 in a field as
01234567890 ?

No, it won't treat these the same.
If so I don't need to go through the painful process of
removing several thousand spaces...

You'll have to go through the process of removing the spaces, but who gave
you the idea that this would be a painful process? A simple update query
should do the trick. Of course, you will only run any type of action query
(Update, Append, Delete or Make Table) ONLY after making a backup of your
database, in case something goes horribly wrong.

So, after you have your backup safely made, fire up a new query and go
directly to the SQL View. By the way, I didn't explain this before, but when
you create a query using the QBE (Query By Example) grid, Access is actually
writing the SQL statement for you in the background. By default, Access uses
the JET database engine, although one can use other database engines, such as
SQL Server, Oracle, Sybase, etc. with an Access application. Anyways, the
language that RDBMS (Relational DataBase Management Systems) speak is SQL,
which you now know stands for Structured Query Language. An excellent way to
start learning SQL is to look at queries you have created in the normal QBE
design view, by displaying the corresponding SQL view. Not all SQL statements
can be represented in the more familiar design view, but most of them can be.
Another good resource is to pick up a copy of the book "SQL Queries for Mere
Mortals", by John Viescas.

Okay, so back to that SQL statement that you will need. It would look
something like this, assuming you are running Access 2000 or later (the
built-in Replace function was introduced in Access 2000):

UPDATE [Table Name]
SET [Table Name].[Field Name] = Replace([Field Name],Chr(32),"")
WHERE [Table Name].[Field Name] Is Not Null


[Table Name] is the name of your table and [Field Name] is the name of the
field that you need to update. Make the appropriate substitutions in the
names indicated in the SQL statement. My example even includes spaces in both
the table and field names. Just don't forget to make that backup copy first,
before running this update query!


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

NickTheBatMan said:
Hi Nick,
The OTHER problem I had was that I'd named the table as 2 separate
words and as I've found Access doesn't like that either...

Well, Access (and the JET database engine) can deal with this fine, as long
as you always remember to surround any references to objects with spaces in
their names with square brackets. For example, [Order Details]. The sample
Northwind.mdb database is just full of bad naming examples that violate
Microsoft's own guidelines!

Ah ha, thank you for that, another thing learnt :) Good to see that
MS provide good examples as usual ;)
You're welcome. May I suggest that you download a copy of a zipped Word
document that I call "Access Links.doc"? I plan on reposting this document as
a better organized web page sometime in the future, but for now it is a Word
document. I recommend that you pay really close attention to the first (3)
pages, and also to the two links shown in red font on page 4. Just skim the
rest of the document every now and then, so that you have a general idea of
the types of information that it includes. But pay really good attention to
the first three pages in particular. You can download a zipped copy from here:

http://www.accessmvp.com/TWickerath/

Thank you again :)
I'm at work and for some reason they won't let me download it - shall
do so at home tonight...
Also, an excellent resource is Access MVP Crystal's Access Basics tutorials,
available here:
http://www.accessmvp.com/Strive4Peace/Index.htm

Many thanks for this too, I shall see what I can work from that too...
You can do this, however, a combo box will only display the first column of
width greater than zero when it is not dropped down. You will only see the
second column when you click on the combo box to open it up. His first
version should do the trick:

SELECT table1.name, table1.home, table1.mobile
FROM table1
WHERE (((table1.home) Is Not Null));

Notice that the concatenation operator (+ sign) has been replaced by a
comma. Make sure that the column count matches (3 in the above case), and
that the column widths are set appropriately.

I'm not sure what you mean by this talking about Combo Box but am sure
I'll learn - using the above I see that Access creates columns where a
comma is inserted into the script, I can now create new tables from
that and get things going as I want...
I'm not understanding you on this issue. Spaces in data values should not be
a problem. The advice to avoid spaces applies to things that you assign a
name to within Access (ie. fields, tables, queries, forms, reports, macros,
modules, controls on forms and reports, variable names, etc.). It does not
apply to spaces that are a part of the data stored in the tables.

Ah, so Access will see 01234 567 890 or 01 234 567 890 in a field as
01234567890 ? If so I don't need to go through the painful process of
removing several thousand spaces...

As I think I said, I'm working on a db that has already been produced
in a certain format and am trying to import loads of data from
documents and spreadsheets that have been produced in other formats by
other people ! :eek:

Many thanks again Tom :)
If I need any more assistance I'll be back...

Nick
__________________________________________











- Show quoted text -
 
T

Tom Wickerath

PS. I forgot to explain something with this update query:

UPDATE [Table Name]
SET [Table Name].[Field Name] = Replace([Field Name],Chr(32),"")
WHERE [Table Name].[Field Name] Is Not Null


Chr(32) is using the built-in Chr function; 32 is the ASCII code for a
space. The "" (two quotes in a row, without anything in-between) is a zero
length string, often times abbreviated as ZLS. The general format of the
Replace function is this:

Replace(expression, find, replace[, start[, count[, compare]]])

expression
Required. String expression containing substring to replace.

find
Required. Substring being searched for.

replace
Required. Replacement substring.

start
Optional. Position within expression where substring search is to begin. If
omitted, 1 is assumed.

count
Optional. Number of substring substitutions to perform. If omitted, the
default value is –1, which means make all possible substitutions.

compare
Optional. Numeric value indicating the kind of comparison to use when
evaluating substrings. See Settings section for values.

I did not use the three optional parameters: start, count and compare in the
SQL statement that I gave you. The expression part would be your field name.
The find part is Chr(32) (ie. find all spaces), and the replace part is a ZLS.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
 
N

NickTheBatMan

PS. I forgot to explain something with this update query:

UPDATE [Table Name]
SET [Table Name].[Field Name] = Replace([Field Name],Chr(32),"")
WHERE [Table Name].[Field Name] Is Not Null

Chr(32) is using the built-in Chr function; 32 is the ASCII code for a
space. The "" (two quotes in a row, without anything in-between) is a zero
length string, often times abbreviated as ZLS. The general format of the
Replace function is this:

Replace(expression, find, replace[, start[, count[, compare]]])

expression
Required. String expression containing substring to replace.

find
Required. Substring being searched for.

replace
Required. Replacement substring.

start
Optional. Position within expression where substring search is to begin. If
omitted, 1 is assumed.

count
Optional. Number of substring substitutions to perform. If omitted, the
default value is -1, which means make all possible substitutions.

compare
Optional. Numeric value indicating the kind of comparison to use when
evaluating substrings. See Settings section for values.

I did not use the three optional parameters: start, count and compare in the
SQL statement that I gave you. The expression part would be your field name.
The find part is Chr(32) (ie. find all spaces), and the replace part is a ZLS.

Tom Wickerath
Microsoft Access MVPhttp://www.accessmvp.com/TWickerath/http://www.access.qbuilt.com/html/expert_contributors.html

WOW Tom that's all really useful, MANY thanks for that :)

I shall continue working at it and if I get stuck again I'll ask...
hopefully you've answered most of my questions so far...:)

Nick
 
Top