Access databases and VB

Moderators: Gogi
Number of threads: 767
Number of posts: 1599

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Error 3061 Posted by turkee on 5 Dec 2012 at 8:57 PM
I have a module as an event to a form. It is designed to collect multiple customer_id from user and then run a report which outputs a PDF file for each customer_id.
I'm getting the error 3061 on the sql string. Here is the code:
Anybody know a solution? I searched all over for this and still no solution.

Sub Command21_Click()

'------------------------------------------
'On Error GoTo Err_Handler
'Purpose: Open the report filtered to the items selected in the list box.
'Author: Allen J Browne, 2004. http://allenbrowne.com
'----------------------------------------------
'glbVarName As String
Dim rs As DAO.Recordset
Dim sql As String
Dim strPath As String
TempVars.Add "strvndCode", Null 'Me.cboProdCode.Value
TempVars.Add "StartDate", Me.StartDate.Value
TempVars.Add "EndDate", Me.EndDate.Value
'-----------------------------------------------
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.
strDelim = """" 'Delimiter appropriate to field type. See note 1.
strDoc = "test pdf"
'MsgBox strDoc
'Loop through the ItemsSelected in the list box.
With Me.NamesList 'LstCategory
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
' strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim & ","
strWhere = strWhere & .ItemData(varItem) & ","
'Build up the description from the text in the visible column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
End If
Next
End With

'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Customer_ID] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Categories: " & Left$(strDescrip, lngLen)
End If
End If

'Report will not filter if open, so close it. For Access 97, see note 3.
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If
strPath = "C:\Access\"
sql = "SELECT DISTINCT TempTablePDF.Customer_id FROM TempTablePDF where '" & strWhere & "' and invoice_date between '#startdate#' and '#enddate#';"[/color]Set rs = CurrentDb().OpenRecordset(sql, dbOpenSnapshot)
Do While Not rs.EOF
strVndCode = rs!Customer_id
TempVars.Add "strvndCode", strVndCode
OpenArgs:=strDescrip

DoCmd.OutputTo acOutputReport, strDoc, acFormatPDF, strPath & strVndCode & ".pdf"
rs.MoveNext
Loop

Set rs = Nothing
End Sub



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.