I have a query that generates a top percentile random order followed by an Append query to insert those selections into a History Table. my problem is that because I'm returning a random order, the data that's appended to the history table does not match the data from my random query. The code is as follows:
Code:
Private Sub btnTest2_Click()
Dim StrSql As String
Dim qDef As QueryDef
Dim Cust As Long
Dim AppQ As String
Randomize
StrSql = "SELECT TOP " & Nz(Me.PercentCombo, 100) & " PERCENT DonorT.DonorID, DonorT.DonorFirstName, DonorT.DonorLastName, DonorT.DonorGroupID, DonorT.DonorIsActive, Rnd([DonorID]*Timer()*-1) AS X, CustomerT.OrganizationID"
StrSql = StrSql & " FROM OfficerEmployerT RIGHT JOIN (CustomerT RIGHT JOIN (GroupT INNER JOIN DonorT ON GroupT.GroupID = DonorT.DonorGroupID) ON CustomerT.OrganizationID = DonorT.OrganizationID) " _
& "ON OfficerEmployerT.OfficerID = DonorT.OfficerID"
StrSql = StrSql & " WHERE CustomerT.OrganizationID=[Forms]![RandomF]![CustomerCombo] AND DonorT.DonorGroupID=[Forms]![RandomF]![GroupCombo] AND DonorIsActive=True"
StrSql = StrSql & " ORDER BY Rnd([DonorID]*Timer()*-1);"
Set qDef = CurrentDb.QueryDefs("RandomQ")
qDef.SQL = StrSql
qDef.Close
Set qDef = Nothing
Randomize
DoCmd.OpenQuery "RandomQ"
AppQ = "INSERT INTO RandomT(DonorID, DonorFirstName, DonorLastName, GroupID, OrganizationID) " & _
"SELECT DonorID, DonorFirstName, DonorLastName, DonorGroupID, OrganizationID " & _
"FROM RandomQ"
If MsgBox("Are these the random selections that will be tested?" & vbNewLine & "If not, select NO and run again", vbYesNo, "Official Random Selections") = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunSQL AppQ
DoCmd.SetWarnings True
Else
DoCmd.Close acQuery, "RandomQ"
End If
End Sub
Any help would be greatly appreciated. Thanks
Also, some help on how to better randomize these selections would be awesome