VB Coding

  • Thread starter Thread starter AlbertaRose
  • Start date Start date
A

AlbertaRose

I am trying to duplicate a record the number of times as indicated in the
field on a form. For example, if I'm ordering 12 plates of steel, but need
them to be tracked individually, I'd like to be able to input all the
information one time and write VB code to tell Access to go and look in the
field that contains the volume and duplicate this record that many times. It
could be any volume from 2 to 200 if necessary. I also have another field
that does autonumber for tracking purposes. Any ideas?
 
AlbertaRose,

You might try something like the following in the click event of a command
button to process the order on your form. I made some assumptions about your
order table(s) and form, but hopefully you'll be able to understand the
example.

Private Sub cmdProcessOrder_Click()
Dim rst as DAO.Recordset
Dim strOrderItem As String
Dim i as Integer
Dim intDuplicateRecordCount as Integer

intDuplicateRecordCount = Me.txtRecordCount 'This would be your field
where the item volume would very from 2 to 200

Set rst = CurrentDb.OpenRecordset("tblOrders")
With rst
For i = 1 to intDuplicateRecordCount
.AddNew
.Fields("OrderNumber").Value = strOrderNumber
'Add additional fields required with their associated variable
'values from the order entry form.
.Update
Next i
End with
rst.Close
Set rst = Nothing
End Sub


Ken Warthen
(e-mail address removed)
 
one thing you might consider is there any relationship between the 2-200
pieces that have common data?

such as date ordered, date approved, Foreman etc...

The reason why I ask this, you might use a slightly more relational
approach. The above fields would NOT have to be duplicated for each of the
plates need. the choice in this matter likely revolves around if there is a
common set of data for the "set" of pieces. The advantage of the relational
approach is if you change information for the "set", it is automatic applied
to each of the pieces in that set without any additional coding....

The above idea really only applies if there is a "common" data for that
"set" of plates....
 
Back
Top