Solved

DoCmd.OpenReport Syntax Error (Comma in query expression)

Posted on 2011-03-04
3
600 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA script to check for duplicate primary keys on lost focus 18 30
Access on Mouse move 5 31
Access Open Report with SQL Parameter 11 29
aggregate query? 7 35
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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