I have a table that does not have a primary key. The user keys in a unique
number as the key field when they add a record.
So? why not make this field the Primary Key? It's unique; it's stable;
it's short - the criteria for a Primary Key. Don't fall for
Microsoft's implication that a Primary Key should be an Autonumber!
They have the need to add
multiple records that have the same information except for the key field
number they key in. they would like to be "asked" How Many Records Do You
Want To Add? key in an amount (5 for example) then key the information
once and have the database add the 5 records with the same data incrementing
the unique number field by 1.
Any Ideas?
You'ld need some VBA code to open a the Form's RecordsetClone and
append records to it - a bit more code than I'm comfortable writing
from scratch here. But consider adapting this button code. It uses an
accessory table Num which contains a single long integer field N, with
values from 0 to 1000.
Private Sub cmdDup_Click()
' Comments : Create txtHowMany dups of current record
' Parameters:
' Created : 05/30/03 17:11 JWV
' Modified :
'
' --------------------------------------------------
Dim strSQL As String
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim iIssue As Integer
On Error GoTo PROC_ERR
' be sure the cost has been calculated
If IsNull(Me.txtCost) Then Call cmdCalc_Click
' Use the Num table as an accessory to add new records
strSQL = "INSERT INTO Ads (InvoiceID, IssueNo, AdTypeID, Width, " _
& "Height, Cost, Color, TearSheet) " _
& "SELECT " & Me!InvoiceID & " AS InvoiceID, [N] + " & Me.IssueNo & "
AS IssueNo, " _
& Me.AdTypeID & " AS AdTypeID, " _
& Nz(Me!txtWidth, 0) & " AS Width, " _
& Nz(Me!txtHeight, 0) & " AS Height, " _
& Me.Cost & " AS Cost, _
& Me.TearSheet & " AS TearSheet " _
& "FROM Num WHERE Num.N < " & Me.txtHowMany & " ORDER BY N;"
Set db = CurrentDb()
Set qd = db.CreateQueryDef("", strSQL)
qd.Execute dbFailOnError
Set qd = Nothing
Set db = Nothing
Me.txtHowMany = 1
Me.Requery
PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox "Error " & Err.Number & _
" in cmdDup_Click in Form_sbfrmAds:" & vbCrLf & Err.Description
Resume PROC_EXIT
End Sub