crosmill
Registered User.
- Local time
- Today, 05:58
- Joined
- Sep 20, 2001
- Messages
- 285
I've reposted this from another post because I've worked out the problem but still don't know how to solve it.
http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=30033
First things first, here's the code
Private Sub Command7_Click()
Dim dbs As Database
Dim rst As Recordset
Dim RanValue As Integer
Dim noLoop As Integer
Dim nolooped As Integer
Dim AccNoOfRecords As Integer
Dim RanNum As Integer
Dim ln As Integer
Dim sqlStr As String
Dim RecordArray As Variant
Dim NoOfRecords As Variant
Set dbs = CurrentDb
'Creates Record ID array
sqlStr = "SELECT * FROM WinnerSelector WHERE [WinnerType] = Null"
Set rst = dbs.OpenRecordset(sqlStr)
While Not rst.EOF
If NoOfRecords = Null Then
NoOfRecords = rst("ID") & ", "
Else
NoOfRecords = NoOfRecords & rst("ID") & ", "
End If
rst.MoveNext
Wend
'Removes Trailing Comma and space
ln = Len(NoOfRecords)
AccNoOfRecords = rst.RecordCount
NoOfRecords = Left(NoOfRecords, (ln - 2))
RecordArray = Array(NoOfRecords)
Set dbs = Nothing
'Selects a Random record excluding those already selected
'and updates Winner Type to that specified
Set dbs = CurrentDb
'Loop no of times requested
noLoop = Me.NoOfPrizes
nolooped = 0
While nolooped < noLoop
Randomize
RanNum = (Int((AccNoOfRecords - 0 + 1) * Rnd) + 0)
RanValue = RecordArray(8) 'RanNum)
sqlStr = "SELECT * FROM WinnerSelector WHERE [ID] = " & RanValue & " AND [WinnerType] = Null"
Set rst = dbs.OpenRecordset(sqlStr)
rst.Edit
rst("WinnerType") = Me.PrizeType
rst.Update
nolooped = nolooped + 1
Wend
Set dbs = Nothing
End Sub
OK
Now, the problem is, RecordArray = Array(NoOfRecords), NoOfRecords contains data similar to "1, 2, 3, 4, 5, 6, 7, 8, 9, 10" the trouble is that the Array is looking at it like Array("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", "more stuff here if you want it") so it's seeing the inserted numbers as a string instead of a series of integers.
Can anyone help?
http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=30033
First things first, here's the code
Private Sub Command7_Click()
Dim dbs As Database
Dim rst As Recordset
Dim RanValue As Integer
Dim noLoop As Integer
Dim nolooped As Integer
Dim AccNoOfRecords As Integer
Dim RanNum As Integer
Dim ln As Integer
Dim sqlStr As String
Dim RecordArray As Variant
Dim NoOfRecords As Variant
Set dbs = CurrentDb
'Creates Record ID array
sqlStr = "SELECT * FROM WinnerSelector WHERE [WinnerType] = Null"
Set rst = dbs.OpenRecordset(sqlStr)
While Not rst.EOF
If NoOfRecords = Null Then
NoOfRecords = rst("ID") & ", "
Else
NoOfRecords = NoOfRecords & rst("ID") & ", "
End If
rst.MoveNext
Wend
'Removes Trailing Comma and space
ln = Len(NoOfRecords)
AccNoOfRecords = rst.RecordCount
NoOfRecords = Left(NoOfRecords, (ln - 2))
RecordArray = Array(NoOfRecords)
Set dbs = Nothing
'Selects a Random record excluding those already selected
'and updates Winner Type to that specified
Set dbs = CurrentDb
'Loop no of times requested
noLoop = Me.NoOfPrizes
nolooped = 0
While nolooped < noLoop
Randomize
RanNum = (Int((AccNoOfRecords - 0 + 1) * Rnd) + 0)
RanValue = RecordArray(8) 'RanNum)
sqlStr = "SELECT * FROM WinnerSelector WHERE [ID] = " & RanValue & " AND [WinnerType] = Null"
Set rst = dbs.OpenRecordset(sqlStr)
rst.Edit
rst("WinnerType") = Me.PrizeType
rst.Update
nolooped = nolooped + 1
Wend
Set dbs = Nothing
End Sub
OK
Now, the problem is, RecordArray = Array(NoOfRecords), NoOfRecords contains data similar to "1, 2, 3, 4, 5, 6, 7, 8, 9, 10" the trouble is that the Array is looking at it like Array("1, 2, 3, 4, 5, 6, 7, 8, 9, 10", "more stuff here if you want it") so it's seeing the inserted numbers as a string instead of a series of integers.
Can anyone help?