Adding sequential records via a Form

  • Thread starter Thread starter shrader
  • Start date Start date
S

shrader

I would like to be able to add multiple sequential records to my table
via a form.

I have a form with two text boxes for the start and end range of
sequential numbers. I have a third text box for a description of the
records. Basically, a small text book inventory form. The start and
end range are numbers assigned to barcodes and the description is the
name of the book (which are all the same).

I am having trouble with the coding behind the form to achieve this.
Many thanks to anyone who can help me.

Best regards,

Mann
 
Mann,

You need a recordset operation to do that, something like (aircode):

Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("MyTable")
For i = Me.txtRangeFrom To Me.txtRangeTo
rst.AddNew
rst.Fields(0) = i
rst.Fields(1) = Me.txtDesciption
rst.Update
Next
rst.Close
Set rst = Nothing
Set db = Nothing

Where I have assumed that the two fields are the first and second in the
table (index 0 and 1 respectively). I hope my name assumption are
self-explanatory, so you can change to your actual names. The code
should be in the form's own module, presumably in a command button's
Click event.

Note: To run this code, an appropriate DAO Object Library reference is
required. While in the VB editor window, go to menu item Tools >
References; check if a Microsoft DAO reference is present among the ones
checked at the top of the list. If not, scroll down to find the
appropriate Microsoft DAO X.X Object Library reference and check it. The
appropriate reference is DAO 3.51 for A97, DAO 3.6 for A2K or later.

HTH,
Nikos
 
Back
Top