1

So I have a query, as shown below, which runs on a parameter.

I was wondering if there is a way to use VBA to set the query parameters. I currently have about 40 queries all exactly the same except for the product ID, and as such I have 40 reports as well... if i have the one query, I will still have to write out the code for the productid in the VBA, but i can use one report instead of that many.

Life would be much easier with just one query and one report and have the VBA set the parameters, as the user does not know the product ID

SELECT TblTotalSale.ProductID, TblProduct.Description, TblTotalSale.Size, TblTotalSale.SalePrice, TblTotalSale.Day
FROM TblProduct INNER JOIN TblTotalSale ON TblProduct.ProductID = TblTotalSale.ProductID
WHERE (((TblTotalSale.ProductID)=[]));

The VBA

Private Sub IPA_Click()

DoCmd.OpenReport "RptProduct", acViewReport, , [TblTotalSale.ProductID="5"]

End Sub

I have also tried tblTotalSale.ProductID = "5" I know I am using SQL where I should be using VBA...

Thanks

Sam

1 Answer 1

6

Do not include a parameter for the sql statement for reports and forms. Use the Where argument of the OpenForm or OpenReport method of the DoCmd object.

DoCmd.OpenReport Method

Sign up to request clarification or add additional context in comments.

2 Comments

so remove the where in the SQL and in the VBA write DoCmd.OpenReport "RptProduct", acViewReport, , TblTotalSale.ProductID=5 ?
With quotes "TblTotalSale.ProductID=5" or for text, "AText='ABC'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.