Page 3 of 3 FirstFirst 123
Results 31 to 45 of 45
  1. #31
    The U is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    25
    I ran into another problem: Apparently my filter can be too long in

    Code:
    DoCmd.OpenReport "Report1", acViewPreview, , strWhere
    I see that the strWhere condition in my case is basically open ended and can be over 32768 characters, which seems to be the limit. I guess that limit cannot be shifted, so is there any other solution?

  2. #32
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    That seems like it would be unworkable for a user. You could add values to a table and use a query join instead of the wherecondition.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #33
    The U is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    25
    I could in principle also do the loop again, which I found quite nice, but it brings me back to my post #21 about how I get Access to append PDFs (or RTFs) to each other.

  4. #34
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I don't know how to do that. If I need multiple items in a single PDF, I just filter the report with all of them in it. I'm having trouble getting my head around a filter that's over 32k characters long. Is there a really long table name or something? What does the filter look like? You can alias the table name to a single letter, use IN(), etc.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #35
    The U is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    25
    You are right that the length restriction should actually not apply. I have at maximum 1400 records of which I select much less. The field Rnumber that is used for searching contains text with maximally 10 characters (but usually only 7). So even if I add three characters (",") to each entry I will never reach 32000 characters in strWhere. However, the table tblRec may have multiple entries of Rnumber but that is why I use SELECT DISTINCT.... Here is the code I am using:

    Code:
    Private Sub OpenRPT_Click()
    Dim db As DAO.Database
    Dim strWhere As String
    Dim myPath As String
    Dim strReportName As String
    Dim rs As DAO.Recordset
    Dim v As String
    Dim varItem As Variant
    Dim strFilter As String
    
    Set db = CurrentDb
    
    
    If AllFinder.ItemsSelected.Count = 0 Then
       MsgBox "Must choose one or more names for report."
       Exit Sub
    End If
    
    For Each varItem In AllFinder.ItemsSelected
       strFilter = strFilter & AllFinder.ItemData(varItem) & "','"
    Next
    
    Set rs = db.OpenRecordset("SELECT DISTINCT Rnumber FROM [tblRec] WHERE Finder IN('" & strFilter & "') ORDER BY Rnumber;")
    Do While Not rs.EOF
        If v = "" Then
            v = rs!Rnumber
        Else
            v = v & "','" & rs!Rnumber
        End If
        rs.MoveNext
    Loop
    
    strWhere = "Rnumber IN ('" & v & "')"
    DoCmd.OpenReport "rptLL", acViewPreview, , strWhere
    myPath = CurrentProject.Path & "\"
    strReportName = "LL.pdf"
    DoCmd.OutputTo acOutputReport, "rptLL", acFormatPDF, myPath & strReportName, False
    DoCmd.Close acReport, "rptLL"
    
    rs.Close: Set rs = Nothing
    db.Close: Set db = Nothing
    
    End Sub

  6. #36
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Just a comment about the code.
    Code:
    rs.Close: Set rs = Nothing
    db.Close: Set db = Nothing
    This is poor programming practice.
    1) You should use only one statement per line. Don't use the (Visual) BASIC line separator character ( : ). Why you ask? Because its use has been deprecated.
    (Deprecated: should be avoided in new code, and likely to become obsolete in a later version of the API)
    It was used in the early versions to conserve memory.
    Jumping into the way-back machine, I once bought 1MB (yes, mega-byte) of RAM for $100. That was for 9 chips - one chip for each bit (one word) and one for parity.
    Back then, you used special characters to declare on-the-fly the variable type. This too has been deprecated.
    I still see code that looks like "Msg$"....
    The dollar sigh defines the variable as a string.
    Here is a list of other deprecated special characters:
    & -> Long
    % -> Integer
    # -> Double
    ! -> Single
    @ -> Decimal
    $ -> String

    2) It makes the code harder to read. Here is some of your code with the line separator character ( : )
    Code:
    Set db = CurrentDb
    
    If AllFinder.ItemsSelected.Count = 0 Then:MsgBox "Must choose one or more names for report.": Exit Sub:End If
    
    For Each varItem In AllFinder.ItemsSelected:   strFilter = strFilter & AllFinder.ItemData(varItem) & "','":Next
    
    Set rs = db.OpenRecordset("SELECT DISTINCT Rnumber FROM [tblRec] WHERE Finder IN('" & strFilter & "') ORDER BY Rnumber;")
    Do While Not rs.EOF:    If v = "" Then: v = rs!Rnumber: Else: v = v & "','" & rs!Rnumber: End If: rs.MoveNext:Loop
    
    strWhere = "Rnumber IN ('" & v & "')":DoCmd.OpenReport "rptLL", acViewPreview, , strWhere:myPath = CurrentProject.Path & "\":strReportName = "LL.pdf":DoCmd.OutputTo acOutputReport, "rptLL", acFormatPDF, myPath & strReportName, False:DoCmd.Close acReport, "rptLL"
    
    rs.Close:Set rs = Nothing
    db.Close:Set db = Nothing
    
    End Sub
    Ugh! Try and make sense of that.



    Looking at these two lines:
    Code:
    rs.Close:Set rs = Nothing
    db.Close:Set db = Nothing
    3) The rule is "If you open it, close it. If you create it, destroy it"
    The recordset RS is OK. You created it (using the SET command) and opened it (using the OpenRecordset command)
    But for database "DB", you created it (using the SET command), BUT you did not open it.
    So the code should be
    Code:
    rs.Close
    Set rs = Nothing
    Set db = Nothing

  7. #37
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    So I'm confused (not unusual). Does the code work with just a few selections? If not, what error are you getting? What does the string look like at that point:

    BaldyWeb-Immediate window
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #38
    The U is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    25
    Thanks, ssanfu, I was not aware of that. I changed my code accordingly.

    pbaldy, yes, it does work with a smaller selection. I used the Immediate window on a case where an error occurs. In my opinion the string is long but looks in principle fine (see below). However, it is actually only 3700 characters. Why does Access think it is over 32000?

    Code:
    Rnumber IN ('5343053','5346502','5346505','5346506','5346509','5346510','5346511','5346513','5346515','5346517','5346518','5346522','5346528','5346530','5346537','5346538','5346541','5346543','5346546','5346548','5346552','5346565','5346567','5346571','5346576','5346580','5346583','5346587','5346589','5346592','5346593','5346594','5346596','5346600','5346602','5346603','5346604','5346605','5346612','5346613','5346615','5346620','5346624','5346627','5346629','5346636','5346637','5346638','5346651','5346653','5346654','5346655','5346657','5346659','5346660','5346661','5346662','5346663','5346664','5346665','5346669','5346671','5346674','5346676','5346681','5346683','5346688','5346689','5346696','5346699','5346704','5346707','5346710','5350001','5350002','5350005','5350006','5350008','5350009','5350012','5350015','5350016','5350018','5350020','5350023','5350025','5350026','5350027','5350028','5350029','5350030','5350031','5350033','5350036','5350037','5350040','5350042','5350043','5350045','5350047','5350049
    ','5350050','5350051','5350052','5350054','5350055','5350056','5350058','5350060','5350061','5350062','5350065','5350068','5350069','5350070','5350071','5350072','5350073','5350074','5350075','5350098','5350102','5350117','5350121','5350126','5350145','5350147','5350148','5350149','5350150','5350185','5350206','5350208','5350213','5350214','5350217','5350226','5350230','5350235','5350236','5350237','5350239','5350243','5350246','5350247','5350248','5350250','5350253','5350254','5350255','5350257','5350259','5350260','5350261','5350262','5350266','5350267','5350268','5350269','5350273','5350274','5350275','5350276','5350278','5350283','5350284','5350285','5350288','5350289','5350290','5350291','5350292','5350296','5350298','5350300','5350302','5350303','5350304','5350308','5350309','5350317','5350319','5350320','5350322','5350325','5350327','5350328','5350332','5350333','5350335','5350336','5350337','5350338','5350339','5350340','5350341','5350342','5350343','5350344','5350345','5350347','5350350','5350451','
    5350452','5350453','5350454','5350455','5350456','5350457','5350458','5350459','5350461','5350462','5350464','5350467','5350469','5350470','5350471','5350472','5350474','5350477','5350484','5350486','5350487','5350492','5350494','5350495','5350498','5350499','5352001','5352003','5352005','5352007','5352014','5352016','5352018','5352019','5352022','5352029','5352033','5352035','5352038','5352039','5352041','5352046','5352047','5352049','5352067','5352093','5352094','5352095','5352098','5352135','5352143','5352146','5352147','5352150','5352161','5352182','5352189','5354462','5354463','5354464','5354466','5354470','5354473','5354474','5354478','5354481','5354485','5354486','5354487','5354489','5354491','5354492','5354494','5354496','5354499','5354502','5354512','5354516','5354518','5354529','5354537','5354545','5354548','5405051','5405052','5405064','5405066','5405073','5405074','5405075','5405077','5405083','5405086','5405087','5405091','5405092','5405093','5405100','5409001','5409002','5409004','5409005','540
    9006','5409008','5409010','5409011','5409014','5409018','5409020','5409022','5409031','5409034','5409035','5409038','5409040','5409041','5409058','5409062','5409077','5409086','5410854','5410855','5411759','5411762','5411765','5411767','5411768','5411775','5411776','5411781','5411782','5411787','5411788','5411790','5411800','5412038','5412045','5412048','5412055','5412058','5412060','5412065','5412067','5412068','5412070','5412090','5412095','5412105','5412106','5412115','5412118','5412128','5412130','5412135','5412137','5412141','5412142','5412150','5412168','5412203','5412215','5412294','5412300','5412308','5412311')

  9. #39
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    What error do you get, and on what line?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #40
    The U is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    25
    So the error message is: "Run-time error '7769': The filter operation was canceled. The filter would be too long." When I go to debug it highlights this row:
    Code:
    DoCmd.OpenReport "rptLL", acViewPreview, , strWhere
    strWhere as is shown above. However, in my opinion strWhere is much shorter than Access' limit. I am confused.

  11. #41
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I'm stumped. Perhaps IN() has a limit on the number of items. The only workaround that comes to mind is the one I mentioned earlier. Populate a table with the selected values, and have the report based on a query that joins to that table on the appropriate field.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #42
    The U is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    25
    OK. But how does the query need to look like? I changed my code to

    Code:
    Private Sub OpenLifeList_Click()
    Dim db As DAO.Database
    Dim strWhere As String
    Dim myPath As String
    Dim strReportName As String
    Dim varItem As Variant
    Dim strFilter As String
    
    Set db = CurrentDb
    
    strWhere = "DELETE * FROM tblLLF"
    db.Execute strWhere
    
    If AllF.ItemsSelected.Count = 0 Then
       MsgBox "Must choose one or more names for report."
       Exit Sub
    End If
    
    For Each varItem In AllF.ItemsSelected
       strFilter = strFilter & AllF.ItemData(varItem) & "','"
    Next
    
    strWhere = "INSERT INTO tblLLF SELECT DISTINCT Rnumber, F FROM [tblR] WHERE F IN('" & strFilter & "') ORDER BY Rnumber;"
    db.Execute strWhere
    
    DoCmd.OpenReport "rptLL", acViewPreview, qryLLF
    The query qryLLF at the moment basically only gets all Rnumbers from tblLLF. When I execute my code, then there is no filter applied, so I suspect that the query needs to hold different/more data.

  13. #43
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No, inside the loop you'd append a record to a table that just had a field for Finder (you'd empty the table before the loop). Then rather than opening the report with a filter, the query the report is based on would join to this new table. If you can attach the db here, I'll play with it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #44
    The U is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    25
    OK, I managed to implement it myself. Thanks a lot for your help!

  15. #45
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Excellent! Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 3 of 3 FirstFirst 123
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-17-2016, 11:20 AM
  2. how to open pass through query with recordset
    By adnancanada in forum Queries
    Replies: 7
    Last Post: 01-13-2016, 11:25 AM
  3. Replies: 6
    Last Post: 10-27-2014, 08:05 PM
  4. Replies: 9
    Last Post: 06-27-2014, 08:23 PM
  5. Pass date and open outlook
    By jaykappy in forum Programming
    Replies: 3
    Last Post: 10-04-2012, 07:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums