good day to all,
I am here again seeking help on my DB..
Below is a code I found in the net and I modified it.
The code work when directly record the selected into the Table,
But what I want is that when I press the command button, it will add the selected data in the Subform "TblPOParticular Subform" from mainform "TblPurchaseOrder" such subform is bound to the Table "TblPOParticular"
I am here again seeking help on my DB..
Below is a code I found in the net and I modified it.
The code work when directly record the selected into the Table,
But what I want is that when I press the command button, it will add the selected data in the Subform "TblPOParticular Subform" from mainform "TblPurchaseOrder" such subform is bound to the Table "TblPOParticular"
Code:
Option Compare Database
Private Sub Command12_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()
Set rs = db.OpenRecordset("TblPOParticular", dbOpenDynaset, dbAppendOnly)
'add selected value(s) to table
Set ctl = Me.List10
For Each varItem In ctl.ItemsSelected
rs.AddNew
rs!ItemDescription = ctl.ItemData(varItem)
rs!POUnit = DLookup("[Unit]", "TblLotParticular", "[LotParticularID]=" & ctl.ItemData(varItem))
rs!POQuantity = DLookup("[Quantity]", "TblLotParticular", "[LotParticularID]=" & ctl.ItemData(varItem))
rs!POCost = DLookup("[Cost]", "TblLotParticular", "[LotParticularID]=" & ctl.ItemData(varItem))
rs.Update
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
Attachments
Last edited: