Full Version: adding duplicate records using vba loop
UtterAccess Discussion Forums > Microsoft® Access > Access Modules
mikewill
Hi
can anyone help me get the iteration in context for this operation correct. I thought I had it but it just starting adding records add infinitum!! It should only add duplicates equal to "quantity" which is a box on the form.

The code is as follows :-

Private Sub Command43_Click()
On Error GoTo Err_Command43_Click
Dim counter
Dim quantity As Integer

counter = 0 ' Initialize variables.
Do While counter < Me.quantity ' Outer loop.
counter = counter + 1 ' Increment Counter.
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Loop


Exit_Command43_Click:
Exit Sub

Err_Command43_Click:
MsgBox Err.Description
Resume Exit_Command43_Click

End Sub

Many thanks Mike
gideon
Replace

Do While counter < Me.quantity

with

Do While counter < Int(Me.quantity)


Good luck.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.