Solved

DoCmd.OpenReport Syntax Error (Comma in query expression)

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

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now