Question : how to get a field to randomly change.

Hi EE
I have a question that i cant find an answer to:
I have a sales form which records each status when a sales person attempts to make a call. I want the form after it has recorded 12 "No Answers" to change the sales person who owns that lead.

This bit is easy however lets say i hav 6 sales people, if sales person 1 owns a lead and after 12 atempts it changes owner to sales person 2 this would work but if i have 6 people how do i get sales person 6 to go to 1?
if i just used a formula that was +1 this would work for all but the last

also it would be even better if i could get it to randomly give it to the next so EG
sales person could pass to anyone randomly etc etc


SO:
I already have a query that counts status's so the form knows when it gets to the 12 number.#
How do i get the form to change the field that contains the owner name to anyone at random?

Sales people names are kept in a seperate table.

Answer : how to get a field to randomly change.

With only 5 other possibilities, it'd be somewhat iffy to get a truly random item, but you can do use the Rnd and Randomize function as shown below to "order" a temporary table in random order. I had a table named "tCustomers", and built a query to show my new randomly ordered data.

See this site, where I shamelessly copied the core ideas for this method: http://www.fontstuff.com/vba/vbatut02.htm

Note that I added a query named "qryRandomRecords". The SQL for that query is:

SELECT TOP 25 tmpCustomers.sName, tmpCustomers.sStreet, tmpCustomers.RandomNumber
FROM tmpCustomers
ORDER BY tmpCustomers.RandomNumber;

You could use this to build a temp table for your salespeople, then just grab the first record returned by that query:

Dim rst As DAO.Recordset
Set rst = Currentdb.OpenRecords("SELECT TOP 1 FROM qryRandomRecords")

Msgbox rst.Fields(0)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
Function GetRandomValues()

Dim rst As DAO.Recordset

DoCmd.DeleteObject acTable, "tmpCustomers"

CurrentDb.Execute "SELECT sName, sStreet INTO tmpCustomers FROM tCustomers"
CurrentDb.Execute "ALTER TABLE tmpCustomers ADD COLUMN RandomNumber DOUBLE"

Set rst = CurrentDb.OpenRecordset("SELECT * FROM tmpCustomers")

Do Until rst.EOF
  Randomize
  rst.Edit
  rst("RandomNumber") = Rnd
  rst.Update
  rst.MoveNext
Loop

DoCmd.OpenQuery "qryRandomRecords"

End Function
Random Solutions  
 
programming4us programming4us