This example shows how to add records to a table named "MyTable", with these
fields:
VoucherID Number field (not AutoNumber)
ClientID field to tell who bought the voucher
PurchaseDate Date/Time when the voucher was bought
Function MakeVoucher(HowMany As Long)
Dim rs As DAO.Recordset
Dim lng As Long
Dim lngLastNumber As Long
Set rs = DBEngine(0)(0).OpenRecordset("MyTable", dbOpenDynaset)
If rs.RecordCount > 0 Then
rs.MoveLast
lngLastNumber = rs!VoucherID
End If
For lng = 1 To HowMany
rs.AddNew
rs!VoucherID = lngLastNumber + lng
rs!ClientID = Forms!MyForm!MyClient
rs!PurchaseDate = Date
rs.Update
Next
rs.Close
MsgBox "New vouchers numbered from " & lngLastNumber + 1
Set rs = Nothing
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Lol" <p0*******@hotmail.com> wrote in message
news:79**************************@posting.google.c om...
My apologies if this has been asked a thousand times before:
I have (to start with) a simple database with a single table and a
single report.
The purpose of the database is to allow gift vouchers to be printed,
each with a unique serial number. To achieve this I have set up a the
table with an autonumber field (my unique serial number) and a report
that looks like a gift voucher including the serial number. Now comes
the tricky bit:
I would like a set up a form whereby I can select a number of vouchers
to print. On entering the number (say 20) the system should create 20
records in my table, which will have the next 20 sequential serial
numbers, and print these last 20 records as vouchers through the
report.
To do this I think I need to find a way to auto create the correct
number of records and then print the report against a select query
which contains the these last 20 records.
Anyone have any ideas?