For one special report that must meet the specification of a third party we must create a database that duplicates each multiple item individually as shown below:
Our records:
Item |
Quantity |
Red widget |
1 |
Yellow Widget |
5 |
Blue Widget |
1 |
Green Widget |
3 |
How it is to be reported:
Item |
Quantity |
Red widget |
1 |
Yellow Widget |
1 |
Yellow Widget |
1 |
Yellow Widget |
1 |
Yellow Widget |
1 |
Yellow Widget |
1 |
Blue Widget |
1 |
Green Widget |
1 |
Green Widget |
1 |
Green Widget |
1 |
We have accomplished the duplication in Excel. Here is the Excel code (Quantity in Column "F"):
Code:
Sub RepeatRows()
Dim lRow As Long
Dim RepeatFactor As Variant
lRow = 1
Do While (Cells(lRow, "A") <> "")
RepeatFactor = Cells(lRow, "F")
If ((RepeatFactor > 1) And IsNumeric(RepeatFactor)) Then
Range(Cells(lRow, "A"), Cells(lRow, "F")).Copy
Range(Cells(lRow + 1, "A"), Cells(lRow + RepeatFactor - 1, "F")).Select
Selection.Insert Shift:=xlDown
lRow = lRow + RepeatFactor - 1
End If
lRow = lRow + 1
Loop
End Sub
I am not up on VBA code for Access so I am looking for help on the code that will do the duplication within Access 2007.