Skip Bisconer
Who Me?
- Local time
- Yesterday, 23:52
- Joined
- Jan 22, 2008
- Messages
- 285
I am trying to append selected records from one table to another but my code doesn't do the trick. The table structures are identical. These are inventory items and I am trying to select certain Vcodes and have those records append to the second table. The rowsource is the Vcode from the first table. The listbox is unbound. There many records per Vcode hence the SELECT DISTINCT on form load.
Any suggestions are appreciated. THanks for looking.
Any suggestions are appreciated. THanks for looking.
Code:
Private Sub Form_Load()
Me.List41.RowSource = "SELECT DISTINCT Vcode FROM tblInventoryAnalysisLoc1 "
End Sub
Private Sub Command6_Click()
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ctl As Control
Dim varItem As Variant
On Error GoTo ErrorHandler
Set db = CurrentDb() [COLOR=green]'tblInventoryAnalysisLoc1[/COLOR]
Set rs = db.OpenRecordset("tblReviewInventoryByMultibleVcode", dbOpenDynaset, dbAppendOnly)
'make sure a selection has been made
If Me.List41.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 position"
Exit Sub
End If
'add selected value(s) to table
Set ctl = Me.List41
For Each varItem In ctl.ItemsSelected
rs.AddNew
rs!VCode = ctl.ItemData(varItem)
rs!Part = Me.Part
rs!Description = Me.Description
rs!WhsLocation = Me.WhsLocation
rs!VendorID = Me.VendorID
rs!VendUOM = Me.VendUOM
rs!VendItemMinOrd = Me.VendItemMinOrd
rs!InventoryCost = Me.InventoryCost
rs!InventoryList = Me.InventoryList
rs!QtyOnOrder = Me.QtyOnOrder
rs!QtyOnBackOrder = Me.QtyOnBackOrder
rs!QtyOnHand = Me.QtyOnHand
rs!QtyMin = Me.QtyMin
rs!QtyMax = Me.QtyMax
rs!AvgMo = Me.AvgMo
rs!ListMargin = Me.ListMargin
rs!LeadTime = Me.InventoryCost
rs!ReviewCycle = Me.ReviewCycle
rs!CarryCost = Me.CarryCost
rs!ReplenishmentCosts = Me.ReplenishmentCosts
rs!SA = Me.SA
rs!SAPcnt = Me.SAPcnt
rs!SP = Me.SP
rs!EOQ = Me.EOQ
rs!Calc1 = Me.Calc1
rs!Calc2 = Me.Calc2
rs!Calc3 = Me.Calc3
rs!LP = Me.LP
rs!OP = Me.OP
rs!OverSP = Me.OverSP
rs!OverInvDollars = Me.OverInvDollars
rs!OverMax = Me.OverMax
rs!TQA = Me.TQA
Next varItem
ExitHandler:
Set rs = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
Select Case Err
Case Else
MsgBox Err.Description
DoCmd.Hourglass False
Resume ExitHandler
End Select
End Sub