Storyteller
Instructor
Hello All,
I am creating a Purchase Order form that uses a list box to show the BarcodeNumber, Description and WholeSaleCost of a Product using this:
SELECT [tblProducts].[BarCodeNumber], [tblProducts].[Description], [tblProducts].[WholeSaleCost] FROM tblProducts WHERE ((([tblProducts].[SupplierID])=[Forms]![frmPurchaseOrders]![POSupplierID])) ORDER BY [tblProducts].[BarCodeNumber];
The List box works properly. I have written the following code to loop through the list box items selected:
Private Sub cmdAddToPO_Click()
' loop through the list box
' whatever records have been selected
' add to tblPurchaseOrderDetails
Dim ctlList As Control
Dim varItem As Variant
Dim intI As Integer
Dim Test As Variant
Set ctlList = Me.List0
For Each varItem In ctlList.ItemsSelected
For intI = 0 To ctlList.ColumnCount - 1
Test = ctlList.Column(intI, varItem)
Debug.Print Test
Next intI
DoCmd.RunSQL "INSERT INTO tblPurchaseOrderDetails ('POBarcodeNumber', 'PODescription', POUnitPrice) VALUES (Test);"
Next varItem
End Sub
I get the following error message: "Number of Query values and Destination Fields are not the same" when I run the code. The Immediate Window shows that the proper values are being used.
Example:
0102709J83
Switch assembly, Astro Spectra vol pot, ch. Sw. & Flex
35.1
tblPurchaseOrderDetails has the following fields:
POID - Number
POBarcodeNumber - Text
PODescription - Text
POUnitPrice - Number
POQuantity - Number
The idea is that the User can select 1 or more items from the listbox click the add button the items selected would then show up in the subformPurchaseOrderDetails (RecordSource: tblPurchaseOrderDetails) and then the User could enter in the Quantity required.
Any suggestions would be greatly appreciated.
Regards,
Michael
I am creating a Purchase Order form that uses a list box to show the BarcodeNumber, Description and WholeSaleCost of a Product using this:
SELECT [tblProducts].[BarCodeNumber], [tblProducts].[Description], [tblProducts].[WholeSaleCost] FROM tblProducts WHERE ((([tblProducts].[SupplierID])=[Forms]![frmPurchaseOrders]![POSupplierID])) ORDER BY [tblProducts].[BarCodeNumber];
The List box works properly. I have written the following code to loop through the list box items selected:
Private Sub cmdAddToPO_Click()
' loop through the list box
' whatever records have been selected
' add to tblPurchaseOrderDetails
Dim ctlList As Control
Dim varItem As Variant
Dim intI As Integer
Dim Test As Variant
Set ctlList = Me.List0
For Each varItem In ctlList.ItemsSelected
For intI = 0 To ctlList.ColumnCount - 1
Test = ctlList.Column(intI, varItem)
Debug.Print Test
Next intI
DoCmd.RunSQL "INSERT INTO tblPurchaseOrderDetails ('POBarcodeNumber', 'PODescription', POUnitPrice) VALUES (Test);"
Next varItem
End Sub
I get the following error message: "Number of Query values and Destination Fields are not the same" when I run the code. The Immediate Window shows that the proper values are being used.
Example:
0102709J83
Switch assembly, Astro Spectra vol pot, ch. Sw. & Flex
35.1
tblPurchaseOrderDetails has the following fields:
POID - Number
POBarcodeNumber - Text
PODescription - Text
POUnitPrice - Number
POQuantity - Number
The idea is that the User can select 1 or more items from the listbox click the add button the items selected would then show up in the subformPurchaseOrderDetails (RecordSource: tblPurchaseOrderDetails) and then the User could enter in the Quantity required.
Any suggestions would be greatly appreciated.
Regards,
Michael