Solved

DoCmd.OpenReport Syntax Error (Comma in query expression)

Posted on 2011-03-04
3
601 Views
Last Modified: 2012-05-11
Trying to run a report from VBA.  The query it uses asks for a parameter.  I'm trying to pass the parameter into the query and getting a syntax error.  The parameter/variable is set prior with a recordset number.

Here's the VBA code:
Dim lngInvoiceNumber As Long
lngInvoiceNumber = rs("tblRepat.Invoice_number")

DoCmd.OpenReport "InvOne", acViewNormal, qryOneInvoice, "[tblRepat.Invoice_number] = " & lngInvoiceNumber & ", , lngInvoiceNumber"

I get an error:
Syntax Error in (comma) in query expression '[tblRepat.Invoice_number] = 423,,lngInvoiceNumber

Using Access 2007

What I'm doing is:
Change the printer to pdf
Pulli a list of all invoices for the day
Looping thru the recordset and converting each invoice to a pdf.  
The query for the report requires an invoice number.

JS
0
Comment
Question by:jshesek
  • 2
3 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35039204

try this first and post your comment

'open report in preview mode

DoCmd.OpenReport "InvOne", acViewPreview, , "[Invoice_number] = " & lngInvoiceNumber

'i am assuming that the record source of the report is table "tblRepat" or a query based on that table
0
 
LVL 1

Author Comment

by:jshesek
ID: 35039694
tblRepat is 1 of the tables the query "qryOneInvoice" pulls from.  
The report InvOne has a data source of qryOneInvoice.  

qryOneInvoice is:
SELECT tblRepat.Invoice_number, tblRepat.[Customer Key Cod], tblRepat.[Invoice date], tblItems.Invoice_number, tblItems.Items, SUM(tblItems.Item_Amt) AS Item_Amt
FROM tblRepat INNER JOIN tblItems ON tblRepat.Invoice_number=tblItems.Invoice_number
WHERE (((tblRepat.Invoice_number)=[ENTER INVOICE NUMBER]))
GROUP BY ;

It came up asking for which invoice_number do you mean - so ran this:
DoCmd.OpenReport "InvOne", acViewPreview, , "[tblRepat.Invoice_number] = " & lngInvoiceNumber

Now a popup window comes up with Enter Invoice Number.  I was hoping lngInvoiceNumber would be passed along.

0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 35039884
you have to remove the Where clause in qryOneInvoice,

SELECT tblRepat.Invoice_number, tblRepat.[Customer Key Cod], tblRepat.[Invoice date], tblItems.Invoice_number, tblItems.Items, SUM(tblItems.Item_Amt) AS Item_Amt
FROM tblRepat INNER JOIN tblItems ON tblRepat.Invoice_number=tblItems.Invoice_number

try again
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question