Sample VBA Code is given below:
Code:
Private Sub Command8_Click()
Dim rst As Recordset
Dim frmNo, toNo, j, bkmk As String
'Read From, To numbers from Text Boxes
frmNo = Nz(Me![From Number], 0)
toNo = Nz(Me![To Number], 0)
'if any of the text box is empty or 0 value
'then display a message and terminate the program
If frmNo = 0 Or toNo = 0 Then
MsgBox "From/To Number is Zero"
Exit Sub
End If
'open the recordset assigned to the Form RecordSource
Set rst = Me.RecordsetClone
'position on the first record
rst.MoveFirst
'set a loop to run from start number to end number
'incrementing by one
For j = frmNo To toNo Step 1
'update the generated number on the record
rst.Edit
rst![numberField] = j
rst.Update
'read the bookmark of the current record
bkmk = rst.Bookmark
'set this bookmark to the Form Bookmark
'This action will synchronize the recordsetclone record
'with the visible record on the form
Me.Bookmark = bkmk
'take the next record in the recordsetclone to
'record the next generated sequence number
rst.MoveNext
'If there are less number of records on the recordset
'than the range of number given to generate then
'then exit the loop and stop generating next number
If rst.EOF Then
Exit For
End If
Next
'close the recordsetclone
rst.Close
Set rst = Nothing
End Sub