Merge? Concatenate?

  • Thread starter jacobe2008 via AccessMonster.com
  • Start date
J

jacobe2008 via AccessMonster.com

Hello...

I have the following two fields:
Field1 Field2
red The apple is
green I love grapes

I want to produce this new field:
Field 3
The apple is red
I love green grapes

How do I produce Field3?

(Note my actual table has about 300 of records. Also note that Field2 is not
consistent).

Thanks in advance!
 
J

John Spencer

Concatenate in a query. There is no reason to redundantly store the data.

Field: [Field2] & " " & [Field1]

If you really, really, really need to do this you could create the new field
and then use an update query to populate the values. However, you would then
need run an update query every time you added a new record or changed an
existing record. Or you must use forms for ALL data entry and have VBA in the
form that would handle populating the new field.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
B

Bob Barrows

jacobe2008 said:
Hello...

I have the following two fields:
Field1 Field2
red The apple is
green I love grapes

I want to produce this new field:
Field 3
The apple is red
I love green grapes

How do I produce Field3?

(Note my actual table has about 300 of records. Also note that
Field2 is not consistent).

Automatically?? No hope in hell, especially if the data in Field2 is not
consistent.

I suppose, and this is entirely off the top of my head, you could add a
table to the database containing a list of words to be modified (I'm
assuming that Field1 contains modifiers that are intended to be used to
modify selected words in Field2). That would be a minimum starting
point.

Then I am thinking that you will need a VBA function to loop through a
submitted string (another assumption: Field2 might contain multiple
keywords to be modified) and insert the supplied modifier before each
keyword in the string. A simple call to the builtin Replace function
won't work because Field2 might contain two or more different keywords,
correct?

You could name the function "AddModifier" and define it to take two
arguments, sToBeModified and sModifier, and return the modified string.
It would do these steps:

Open a shapshot recordset on the table containing the list of keywords
Use split() to create an array containing each of the words in the
sToBeModified string
Loop through the array, looking up each word in the recordset.
If not found, add the word (along with a space) to the string variable
defined to contain the string that will be returned to the caller.
If found, add the sModifier value to the string before adding the word
to the return string

Once that is done, you can create a query that calls the function, like
this:

Select Field1, Field2, AddModifier(Field1, Field2) As ModifiedString
....
 
M

Marshall Barton

jacobe2008 said:
I have the following two fields:
Field1 Field2
red The apple is
green I love grapes

I want to produce this new field:
Field 3
The apple is red
I love green grapes

How do I produce Field3?

(Note my actual table has about 300 of records. Also note that Field2 is not
consistent).


Without some additional information about where to put
field1 in the field2 text, that would require a natural
language parsing procedure. I am unaware of anything that
can do that reliably, so I doubt there is any way to deal
with the general problem.

If you modified the field2 values to include a fixed pattern
at the place where the field1 string should be placed, the
problem is trivially solved by using the Replace function.
For example, if the field2 strings were:

The apple is ??
I love ?? grapes

Then you could use a query like:

SELECT field1, field2, Replace(field2, "??", field1) As
field3
FROM thetable
 
J

John W. Vinson

Hello...

I have the following two fields:
Field1 Field2
red The apple is
green I love grapes

I want to produce this new field:
Field 3
The apple is red
I love green grapes

How do I produce Field3?

(Note my actual table has about 300 of records. Also note that Field2 is not
consistent).

Thanks in advance!

You'll need to explain more about the context. Are you expecting Access (a
primarily mathematical, set-based computer program which treats text as just
meaningless blocks of characters) to understand English grammar and insert the
noun in the proper grammatical location in the sentence? That's certainly NOT
within the program's capabilities, maybe not any computer's, yet.

What real-world problem are you expecting Access to solve?
 

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


Top