Page 1 of 3 123 LastLast
Results 1 to 15 of 45
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Still having trouble running reports with multi select list boxes, and Happy New Year all!


    Good morning!

    When I debug the criteria is correct, yet I'm getting an Expected Array error on the last line "getcriteria()" I have no idea how to fix this, yes I am in over my head. I thank you in advance for any insight you can give me!!

    Code:
    Private Sub Command45_Click() Dim VarItm As Variant
     Dim varitm2 As Variant
     Dim stDocCriteria As String
     Dim stdoccriteria2 As String
     Dim getcriteria As String
     Dim bidstatus As Variant
     Dim mfg As Variant
     
      
      For Each VarItm In bidstatus.ItemsSelected
       stDocCriteria = stDocCriteria & "[bidstatus] = " & bidstatus.Column(0, VarItm) & " OR "
    
    
       Next
       For Each varitm2 In mfg.ItemsSelected
       stdoccriteria2 = stdoccriteria2 & "[mfg] = " & mfg.Column(0, VarItm) & " OR "
    
    
       Next
       If stDocCriteria <> "" Then
       stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
        If stdoccriteria2 <> "" Then
       stdoccriteria2 = Left(stdoccriteria2, Len(stdoccriteria2) - 4)
    
    
       End If
       getcriteria = stDocCriteria & " And " & stdoccriteria2
    
    
            Debug.Print "Get Criteria " & getcriteria
       
       'DoCmd.Openreport "BidReportbyMfrSummary", acPreview, , getcriteria()
    
    
       DoCmd.Openreport "secondBidReportbyMfrSummary", acPreview, , getcriteria()
    
    
    End If
    
    
    End Sub
    Here's from the immediate window: Get Criteria [bidstatus] = Open/Quote And [mfg] = AAB

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746
    Why do you have the () after getcriteria?
    You defined getcriteria as a string not a string array.

    Dim getcriteria As String
    - so no brackets required.

    It seems you are missing some important quotes in your rendered criteria.

  3. #3
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Hi Orange! How are you doing? How do I define as string array? It isn't available when I start typing. I will recheck my quotes. Thank you so much for the direction!!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746
    I'm doing well --in isolation. I don't think you need an array, but I don't know the details of your post.
    You can remove the brackets from getcriteria and see what/if error occurs.

    Do you have some examples of your Report's where criteria that you can post?

  5. #5
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    My report criteria looks like this: [bidstatus] = OpenQuote And [mfg] = Greenheck, when I run a detailed report based on the same criteria I get ALL mfgs. UGH. My debug gives me: Get Criteria [bidstatus] = OpenQuote And [mfg] = Greenheck as well, no quotes? Oh, and I removed the parens and that seemed to help.

    Glad you are well. Hopefully soon we can get out!

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746
    I tried to get a string that "looked " like your requirement with this little test

    Sub test4()
    Dim x As String
    x = """[bidstatus] = 'Open/Quote' And [mfg] = 'AAB'"""
    Debug.Print "OpenReport reportname,acNormal,," & x
    End Sub


    which gives result

    OpenReport reportname,acNormal,,"[bidstatus] = 'Open/Quote' And [mfg] = 'AAB'"

    **As a test you could try opening your report and use the following, to see/confirm if the syntax is correct.


    DoCmd.Openreport "BidReportbyMfrSummary", acPreview, "[bidstatus] = 'Open/Quote' And [mfg] = 'Greenheck'",,"[bidstatus] = 'Open/Quote' And [mfg] = 'Greenheck'"

  7. #7
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,658
    Since your using a Multi-select listbox have you considered an "In" clause?

    Code:
      For Each VarItm In bidstatus.ItemsSelected
       stDocCriteria = stDocCriteria & "'" & bidstatus.Column(0, VarItm) & "'," 
       Next
    
    'code here to strip off trailing ,
    
    X= "[bidstatus] In(" & stDocCriteria  & ")"
    I use a public function for such things.
    Attached is an example file.
    See the third listbox down where you can experiment with the optional arguments.
    Select what column to use and what delimiter you want to use.

    your code could simply look something like

    Code:
    X= "[bidstatus] In(" & getLBX(Me.YourListBoxName,1,,"'")  & ")"
    The result will look like "[bidstatus] In( 'Open/Quote','Close/Quote')"
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  8. #8
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Hi Moke! I have tried an in clause, but have simply had no luck getting correct numbers. The point of the report and subreport is to compare sales during a certain time period by MFR and Bid Status. I started out with a main report and subreport, but realized I can't pass the criteria to the subreport via the selection form. My head hurts thinking about this issue. Thank you for the sample db, very impressive. I have tried so many things! Adding the multi-selections to a text box, separated by commas or "or", adding "in" to the front of the string. Heads spinning, may just scrap it and start over, thank you so much for your time. Happy 2021!

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746
    Did you try running the statement I suggested in post #6 as a test? You could make it a 1 line routine--just to ensure the syntax is correct.

    **As a test you could try opening your report and use the following, to see/confirm if the syntax is correct.


    DoCmd.Openreport "BidReportbyMfrSummary", acPreview, "[bidstatus] = 'Open/Quote' And [mfg] = 'Greenheck'",,"[bidstatus] = 'Open/Quote' And [mfg] = 'Greenheck'"


    Also do you have some examples of your Report's where criteria that you can post? People can help if they knew more of your situation. Some complex criteria or even a copy of the db with some clear instructions would be useful.

  10. #10
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Hi Orange, yes I did try it. It gave me all mfrs and all bidstatus.
    Code:
     DoCmd.Openreport "BidReportbyMfrSummary", acPreview, "[bidstatus] = 'OpenQuote' And [mfg] = 'Greenheck'"
    If I put the criteria directly in the query, I get the correct information. So confused! Thanks again for your time!
    Code:
    SELECT DISTINCTROW ProjectItems.ItemBid, MFGs.MFG, Projects.BidDate, Projects.ProjectName, BidStatus.BidStatusFROM MFGs INNER JOIN (BidStatus INNER JOIN (Projects INNER JOIN ProjectItems ON Projects.ProjectID = ProjectItems.ProjectID) ON BidStatus.BidStatusID = ProjectItems.BidStatusID) ON MFGs.MFGID = ProjectItems.MFGID
    GROUP BY ProjectItems.ItemBid, MFGs.MFG, Projects.BidDate, Projects.ProjectName, BidStatus.BidStatus, ProjectItems.MFGID
    HAVING (((MFGs.MFG)="greenheck") AND ((Projects.BidDate) Between [Forms]![CompareSales]![firstbegindate_beginr] And [Forms]![CompareSales]![firstbegindate_endr]) AND ((BidStatus.BidStatus)="openquote"));

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746
    If it opens and creates a report with all mfrs and all bidstatus, then it seems the "where criteria" are not working.

    Where does your query fit into this?

  12. #12
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    The report itself is built on the query CompareMFG
    Code:
    SELECT DISTINCTROW ProjectItems.ItemBid, MFGs.MFG, Projects.BidDate, Projects.ProjectName, BidStatus.BidStatusFROM MFGs INNER JOIN (BidStatus INNER JOIN (Projects INNER JOIN ProjectItems ON Projects.ProjectID = ProjectItems.ProjectID) ON BidStatus.BidStatusID = ProjectItems.BidStatusID) ON MFGs.MFGID = ProjectItems.MFGID
    GROUP BY ProjectItems.ItemBid, MFGs.MFG, Projects.BidDate, Projects.ProjectName, BidStatus.BidStatus, ProjectItems.MFGID
    HAVING (((Projects.BidDate) Between [Forms]![CompareSales]![firstbegindate_beginr] And [Forms]![CompareSales]![firstbegindate_endr]));

  13. #13
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746
    Try this standalone--I think there is a comma missing. I think the where clause should be the 4th parameter.

    DoCmd.Openreport "BidReportbyMfrSummary", acPreview,, "[bidstatus] = 'OpenQuote' And [mfg] = 'Greenheck'"

  14. #14
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    That was perfect! Correct amount and everything! Thanks Orange!!

    Now to figure out how to get that to work if they select all in one or both list boxes.

  15. #15
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746
    OK Great!

    Now we need some details of the listboxes and their rowsources and what the process of filling the form involves.
    Better if we could have a copy of a test database with instructions of filling the form.
    Would also be helpful if you could show/mock up some of the criteria you will be using.

    Another factor to consider is that REPORTs have their own Sorting and Grouping, so you may not need these in your query -in fact they may be ignored by the report mechanism of Access.

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

Similar Threads

  1. Replies: 15
    Last Post: 11-20-2013, 04:30 PM
  2. Replies: 5
    Last Post: 07-26-2012, 12:59 PM
  3. Multi Select List Box Trouble
    By Subwind in forum Forms
    Replies: 2
    Last Post: 06-06-2012, 04:00 AM
  4. 2 multi select list boxes on one search form
    By woodey2002 in forum Forms
    Replies: 2
    Last Post: 11-05-2010, 12:44 PM
  5. Multi-select List Boxes
    By Rawb in forum Programming
    Replies: 6
    Last Post: 09-21-2010, 09:02 AM

Tags for this Thread

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