Link to home
Start Free TrialLog in
Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScFlag for Zambia

asked on

How to use VBA in Ms Access to input multi combo box rows & columns

I’m now almost finishing my task and everything appear to work very well except one last bit which I thought was the easiest to do, here is a puzzle:

After creating a combo box in ms access with the below query and the VBA to populate the selected columns from the mentioned combo box all is well no issue see below:
Combo Box query
SELECT tblPurchasesDetailslines.PurchaseOrderID, tblPurchasesDetailslines.PurchaseID, tblProducts.ProductID, tblProducts.ProductName, tblPurchasesDetailslines.Quantity, tblPurchasesDetailslines.CostValue, tblPurchasesHeader.StatusStore
FROM (tblPurchasesDetailslines INNER JOIN tblProducts ON tblPurchasesDetailslines.ProductID = tblProducts.ProductID) INNER JOIN tblPurchasesHeader ON tblPurchasesDetailslines.PurchaseID = tblPurchasesHeader.PurchaseID
WHERE (((tblPurchasesDetailslines.PurchaseID)=[Forms]![frmGrn]![CboOrder]) AND ((tblPurchasesHeader.StatusStore) Is Null Or (tblPurchasesHeader.StatusStore)<>"2"));

Open in new window


VBA (used to input now the selected combo box columns)
Private Sub CboProducts_AfterUpdate()
Me.PurchasesID = Forms!frmGrn!txtGrnsCosting
Me.ProductID = Me.CboProducts.Column(2)
Me.Qty = Me.CboProducts.Column(4)
Me.Cost = Me.CboProducts.Column(5)
Me.GrnStockAccName = "Stock"
Me.GrnStockAcc = "114-10-1000"
Me.SuspenseName = "GRN Suspense"
Me.SuspenseAcc = "121-12-1000"
Me.BSIDSTOCK = "2"
Me.BSIDSuspense = "3"
DoCmd.GoToRecord , , acNewRec
Me.Refresh
End Sub

Open in new window

All what I want is to simply capture/input all the rows & columns as per filter combo box instead of just one line. Whatever rows is in the filtered combo box
For example if the filtered combo box is showing 5 rows then all the rows must captured at once using the VBA above



User generated image
Avatar of Natchiket
Natchiket
Flag of United Kingdom of Great Britain and Northern Ireland image

It seems like there is a conceptual problem around the use of combo boxes here.  With a combo box you can only select ONE value from the list.  If there are five values in the list then only one value may be selected.  The alternative is to use a multiselect list-box (not a great idea in continuous forms, or even possible in datasheets afaik). From the way you have structured your question it looks like you are trying to populate a child table based on certain criteria.  Perhaps consider using an INSERT or UPDATE querty to push the values into the table or a recordset  to iterate though the 'combo box query' rows and put the data in the target table?
SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc

ASKER

If you want to capture all the values of the combo just iterate it's columns collection

Sorry sir I'm lost what do mean by  just iterate it's columns collection, kindly give an example I'm sure you have clear answer to my problem.

Regards

Chris
I do agree with you all

Perhaps consider using an INSERT or UPDATE querty to push the values into the table or a recordset  to iterate though the 'combo box query' rows and put the data in the target table?

Can an update query used to populate a subform in ms access?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial