Need help picking out random records without any duplicates (1 Viewer)

Di27

New member
Local time
Today, 00:53
Joined
Apr 9, 2019
Messages
2
I'm trying to create a sort of dialer but I dont want the same person to be dialed on the same day.

I have been able to link it to my customerID and the randomizer works fine and doesnt do 2 in a row but there is a possibility of it happening later in the day.

This is what I am using at the moment to assign the dialer to a customer.

Code:
Public Sub RandomCustomer()
Dim ALL As Double, R As Integer

ALL = MAX.Value

    R = (ALL - 1) * Rnd() + 1
    Do While R = MemId
        R = (ALL - 1) * Rnd() + 1
    Loop
        
Customer.Value = R

End Sub

MemID is just a public integer
ALL is the Maximum number of records I have

I've also experimented on using a query to generate and reorganise my records. I'm having issues then assigning this to Customer.Value so it can be shown on my Form in the order it was placed.

Any help would be appreciated
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:53
Joined
May 21, 2018
Messages
8,463
Without knowing your table structure it is hard to give a specific answer. However the normal trick is to sort a query first sort by count of previous selections then by the random number. This way the top records are the records with the fewest previous selections. Obviously if they have never been picked they are at the top of the list.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:53
Joined
Oct 29, 2018
Messages
21,358
Hi. You could add the date of selection in the table and if the date is today, get the next id, if not, set the date to today. Just a thought...
 

Di27

New member
Local time
Today, 00:53
Joined
Apr 9, 2019
Messages
2
I'm trying to create a sort of dialer but I dont want the same person to be dialed on the same day.

I have been able to link it to my customerID and the randomizer works fine and doesnt do 2 in a row but there is a possibility of it happening later in the day.

This is what I am using at the moment to assign the dialer to a customer.

Code:
Public Sub RandomCustomer()
Dim ALL As Double, R As Integer

ALL = MAX.Value

    R = (ALL - 1) * Rnd() + 1
    Do While R = MemId
        R = (ALL - 1) * Rnd() + 1
    Loop
        
Customer.Value = R

End Sub

MemID is just a public integer
ALL is the Maximum number of records I have

I've also experimented on using a query to generate and reorganise my records. I'm having issues then assigning this to Customer.Value so it can be shown on my Form in the order it was placed.

Any help would be appreciated

Thanks for all the help..

I ended up using a public function in conjunction with an array thanks to this stackoverflow.com/questions/29950638/create-random-number-without-duplicating
Then I added a DLOOKUP as a checker to get rid of potential errors due to empty records
 

Users who are viewing this thread

Top Bottom