Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(Me.listtables)
If IsNull(Me.listtables) Or IsNull(Me.txtrecordcount) Then
MsgBox "Please fill in all the search criteria!", vbOKOnly + vbCritical, _
"Missing Data Found"
ElseIf Me.txtrecordcount > rs.RecordCount Or Me.txtrecordcount <= 0 Then
MsgBox "The table you selected contains " & rs.RecordCount & " records." _
& vbCr & vbCr & "Please select a valid number of records!", _
vbCritical + vbOKOnly, "Invalid Number of Records Requested"
rs.Close
Exit Sub
End If
Dim str As String
Dim SQL As String
Dim c As Control
Dim i As Integer
Dim j As Integer
Dim var As Variant
Dim int1 As Integer
Dim int2 As Integer
Dim intRow As Integer
Dim strRecord As String
Set c = Me.listfields
SQL = "SELECT "
For intRow = 0 To (c.ListCount - 1)
If c.Selected(intRow) Then
SQL = SQL & Me.listtables & "." & c.Column(0, intRow) & ","
End If
Next intRow
SQL = Left(SQL, Len(SQL) - 1)
SQL = SQL & " FROM " & Me.listtables
Set rs = CurrentDb.OpenRecordset(SQL, dbOpenDynaset)
rs.MoveLast
rs.MoveFirst
str = ""
strRecord = ""
var = rs.GetRows(rs.RecordCount)
Randomize
For i = 0 To (Me.txtrecordcount - 1)
int1 = Int(Rnd * (UBound(var, 2) - LBound(var, 2) + 1))
int2 = Int(Rnd * (UBound(var, 2) - LBound(var, 2) + 1))
While int1 = int2
int2 = Int(Rnd * (UBound(var, 2) - LBound(var, 2) + 1))
Wend
For j = LBound(var, 1) To UBound(var, 1)
str = var(j, int1)
var(j, int1) = var(j, int2)
var(j, int2) = str
Next j
Next i
[COLOR="Red"]Debug.Print vbCr[/COLOR]
[COLOR="SeaGreen"]For i = 0 To (Me.txtrecordcount - 1)
For j = LBound(var, 1) To UBound(var, 1)
strRecord = strRecord & var(j, i) & ", "
Next j
strRecord = Left(strRecord, Len(strRecord) - 2)
[COLOR="Red"]Debug.Print strRecord[/COLOR]
strRecord = ""
Next i[/COLOR]
rs.Close
Set rs = Nothing