Originally Posted by
Perceptus
There may be a better way to do this with arrays and such. seeding the contents of the array with numbers and then removing those portions of the array as you cycle down through. Im concerned my previous post might run a bit long when trying to resolve the last few records.
Thanks - I have to admit I am pretty new to VBA and have not done much OOP in general so I am not sure how to accomplish what you are suggesting.
Here is how the button is currently coded on click. Any other help or ideas is greatly appreciated.
Code:
Private Sub cmdGo_Click()
Dim db As DAO.Database
Dim rstRecords As DAO.Recordset
Dim rs As DAO.Recordset
Dim tdfNew As TableDef
Dim fldNew As Field
Dim i As Integer
Dim K As Integer
Dim Check As String
Set db = CurrentDb
Set rstRecords = db.OpenRecordset("t_County10")
rstRecords.MoveLast
FindRecordCount = rstRecords.RecordCount
i = rstRecords.RecordCount
DoCmd.DeleteObject acTable, "C10_RNG"
'--- create the table
Set tdfNew = db.CreateTableDef("C10_RNG")
'--- add text field (length 20)
Set fldNew = tdfNew.CreateField("RNG_NO", dbLong)
'--- save the new field
tdfNew.Fields.Append fldNew
'--- save the new table design
db.TableDefs.Append tdfNew
'---Initialize your recordset
Set rs = CurrentDb.OpenRecordset("C10_RNG", dbOpenDynaset)
On Error GoTo errhandler
If TxtInput > 32767 Then
MsgBox "Enter a positive, whole number between 1 and 32,767", vbOKOnly, "Input Error"
ElseIf TxtInput < 1 Then
MsgBox "Enter a positive, whole number between 1 and 32,767", vbOKOnly, "Input Error"
End If
'Dim i As Integer
'Dim K As Integer
'Dim Check As String
'i = TxtInput
TxtInput = i
K = 0
Check = T
Do
Do While K < 11
'K = K + 1
Randomize
If K = 0 Then
TxtOutput = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput
rs.Update
K = K + 1
ElseIf K = 1 Then
TxtOutput2 = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput2
rs.Update
K = K + 1
ElseIf K = 2 Then
TxtOutput3 = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput3
rs.Update
K = K + 1
ElseIf K = 3 Then
TxtOutput4 = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput4
rs.Update
K = K + 1
ElseIf K = 4 Then
TxtOutput5 = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput5
rs.Update
K = K + 1
ElseIf K = 5 Then
TxtOutput6 = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput6
rs.Update
K = K + 1
ElseIf K = 6 Then
TxtOutput7 = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput7
rs.Update
K = K + 1
ElseIf K = 7 Then
TxtOutput8 = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput8
rs.Update
K = K + 1
ElseIf K = 8 Then
TxtOutput9 = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput9
rs.Update
K = K + 1
ElseIf K = 9 Then
TxtOutput10 = Fix(i * Rnd) + 1
rs.AddNew
rs.Fields(0).Value = TxtOutput10
rs.Update
K = K + 1
Check = f
Exit Do
End If
Loop
Loop Until Check = f
Exit Sub
errhandler:
If Err.Number = 11 Or Err.Number = 13 Then
MsgBox "Enter a positive, whole number between 1 and 32,767", vbOKOnly, "Input Error"
End If
End Sub