A
adurrschmidt via AccessMonster.com
Monsters,
I have a simple form with a command button containing code to automatically
create "x" amount of records with the same data for all fields except the
primary key (unique ID). I know that sounds weird but It's something that I
need it to do.
My problem is that I cannot figure out how to get the Dmax() + 1 function to
increment my primary key before the rest of the code runs. As the code
creates new records with the same data, it also seems to be creating the same
primary key over which will not allow the code to finish running and the
"cannot have duplicate values in primary key" error pops up...Is there any
one that can help???
Is there some way to get the primary key to update before each new record is
added?
Option Compare Database
Private Sub Add_Records_Click()
On Error GoTo Err_Add_Records_Click
Dim SampleCounter As Integer
SampleCounter = [Forms]![Frm1]![SampleCounter]
Dim Check, Counter
Check = True: Counter = 0
Do
Do While Counter < SampleCounter
Counter = Counter + 1
'Here is where I thought I could use the Dmax() function to update the
primary key, but so far I've had no luck
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
If Counter = SampleCounter Then
Check = False
Exit Do
End If
Loop
Loop Until Check = False
Exit_Add_Records_Click:
Exit Sub
Err_Add_Records_Click:
MsgBox Err.Description
Resume Exit_Add_Records_Click
End Sub
I have a simple form with a command button containing code to automatically
create "x" amount of records with the same data for all fields except the
primary key (unique ID). I know that sounds weird but It's something that I
need it to do.
My problem is that I cannot figure out how to get the Dmax() + 1 function to
increment my primary key before the rest of the code runs. As the code
creates new records with the same data, it also seems to be creating the same
primary key over which will not allow the code to finish running and the
"cannot have duplicate values in primary key" error pops up...Is there any
one that can help???
Is there some way to get the primary key to update before each new record is
added?
Option Compare Database
Private Sub Add_Records_Click()
On Error GoTo Err_Add_Records_Click
Dim SampleCounter As Integer
SampleCounter = [Forms]![Frm1]![SampleCounter]
Dim Check, Counter
Check = True: Counter = 0
Do
Do While Counter < SampleCounter
Counter = Counter + 1
'Here is where I thought I could use the Dmax() function to update the
primary key, but so far I've had no luck
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
If Counter = SampleCounter Then
Check = False
Exit Do
End If
Loop
Loop Until Check = False
Exit_Add_Records_Click:
Exit Sub
Err_Add_Records_Click:
MsgBox Err.Description
Resume Exit_Add_Records_Click
End Sub