VBA Append Multiple Random Records to Row

C

CHAVOUSA

I am using MS Access VBA.
I have a database with two tables..Products and Keywords. In the Products
table I have a field named suggested_keywords which is a memo type field and
is currently empty. In the Keywords table, I have about 1000 records. Each
records has an unique keyword value.

What I am trying to accomplish is to update the suggested_keywords field in
all existing Products records with 10 random keyword values each, from the
Keywords table. They would be separated by a comma within that field.
Obviously, each suggested_keywords field in every product record would have a
different combined value because it would update with random values.

I have tried several queries and VBA code samples found on DBforums and other
sites without any success.

Can anyone assist with this or provide some advise? Thanks.

The code below is from two queries I tried using. However, the queries update
all records with only one keyword, and the keyword is the same for all of
them even though I have the rand() function included.

This is called "qryADMIn random keywords"
SELECT keywords.pother3, Rnd(1*Second([keywordid]))*Rnd([keywordid]) AS
sortid FROM keywords;

Then I run this update query
UPDATE products, [qryADMIn random keywords] SET products.suggested_keywords =
[qryADMIn random keywords]![pother3];
 
C

CHAVOUSA

Looked at that thread. It actually just describes a random module which I am
familiar with. The issue I have is with a combination of the random and
updating. And in fact, I need to randomize field content per individual
record, not as a whole. But thanks for the response.

Take a look at http://www.mvps.org/access/queries/qry0011.htm at "The Access
Web".
I am using MS Access VBA.
I have a database with two tables..Products and Keywords. In the Products
[quoted text clipped - 30 lines]
products.suggested_keywords =
[qryADMIn random keywords]![pother3];
 
D

Douglas J. Steele

The point is, you need that Randomize function.

Access tries to help too much, and doesn't always call the function for each
row that's returned. Using that technique should remedy that problem.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


CHAVOUSA said:
Looked at that thread. It actually just describes a random module which I
am
familiar with. The issue I have is with a combination of the random and
updating. And in fact, I need to randomize field content per individual
record, not as a whole. But thanks for the response.

Take a look at http://www.mvps.org/access/queries/qry0011.htm at "The
Access
Web".
I am using MS Access VBA.
I have a database with two tables..Products and Keywords. In the
Products
[quoted text clipped - 30 lines]
products.suggested_keywords =
[qryADMIn random keywords]![pother3];
 
D

David F Cox

rnd() returns random numbers.
rnd(constant) returns the same sequence of random numbers every time, (so
you can reproduce results)
 

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

Top