Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DoCmd.OpenReport Syntax Error (Comma in query expression)

Posted on 2011-03-04
3
Medium Priority
?
607 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA 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…

730 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