openReport

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bryonone
    New Member
    • Jul 2021
    • 4

    openReport

    Trying to open a report with multiple WHEREconditions . I have 4 strings (SelA, SelB, SelC, whereStr) all defined as strings.

    SelA, SelB SelC all pieces of the whereStr

    If I set whereStr = {any of the individual strings A,B or C}, the following works

    DoCmd.OpenRepor t "rptName", acViewReport , , whereStr

    When I try to concatenate the stings into 'whereStr', I only get the first string listed in the report.

    Anyone? Help?
  • cactusdata
    Recognized Expert New Member
    • Aug 2007
    • 223

    #2
    Concatenate? How? They are there already: SelA, SelB SelC all pieces of the whereStr

    And do you wish to filter on four fields or one field?

    Comment

    • bryonone
      New Member
      • Jul 2021
      • 4

      #3
      If I set
      whereStr=SelA
      It works fine

      how do I get the whereStr to be equal to SelA, SelB, and SelC.

      I want to filter on all 3 fields.

      Any thoughts?

      Comment

      • cactusdata
        Recognized Expert New Member
        • Aug 2007
        • 223

        #4
        Try with:

        Code:
        whereStr = SelA & " And " & SelB & " And " & SelC

        Comment

        • bryonone
          New Member
          • Jul 2021
          • 4

          #5
          I had tried that before. It only recognizes the first string and ignores the rest. I just tried again triple checking the & and "". Still does not work.

          I also tried in the 'WHERE" entry,
          SelA + SelB + SelC

          Comment

          • cactusdata
            Recognized Expert New Member
            • Aug 2007
            • 223

            #6
            Without the content of SelA, B, and C, we can't help.

            Comment

            • bryonone
              New Member
              • Jul 2021
              • 4

              #7
              Code:
              Dim SelLic, SelSW, SelArea As String
              Dim whereStr As String
              
              SelLic = "[swLicName]= Forms![frmViewLicToLoc]![txtSelectedLicense] _
                  OR Forms![frmViewLicToLoc]![txtSelectedLicense] is null _
                  OR Forms![frmViewLicToLoc]![txtSelectedLicense]=''"
                  
              SelSW = "[swName]=Forms![frmViewLicToLoc]![txtSelectedSW] _
                  OR Forms![frmViewLicToLoc]![txtSelectedSW] is null _
                  OR Forms![frmViewLicToLoc]![txtSelectedSW]=''"
                  
              SelArea = "[areaLocation] = Forms![frmViewLicToLoc]![txtSelectedArea] _
                  OR Forms![frmViewLicToLoc]![txtSelectedArea] is null _
                  OR Forms![frmViewLicToLoc]![txtSelectedArea]=''"
              
                  whereStr = SelSW
              
                  DoCmd.OpenReport "rptViewSearch", acViewReport, , whereStr
              Last edited by twinnyfo; Jul 26 '21, 10:12 AM. Reason: formatted Code

              Comment

              • isladogs
                Recognized Expert Moderator Contributor
                • Jul 2007
                • 483

                #8
                Suggest you look at the code in the two example Databases from my article Multiple Group and Filter.
                These are designed to show ways of building filter criteria when several filter criteria are entered

                Comment

                • cactusdata
                  Recognized Expert New Member
                  • Aug 2007
                  • 223

                  #9
                  Try reducing these like:

                  Code:
                  SelLic = "[swLicName] = Nz(Forms![frmViewLicToLoc]![txtSelectedLicense], [swLicName])"

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32661

                    #10
                    Hi Bryon.

                    I would suggest you're getting in your own way here. Massively overcomplicatin g what should be fundamentally straightforward . See How to Debug SQL String for how to make this much easier for yourself. I suspect once you start following this simple guidance you will no longer need any external help.

                    Can we assume that you understand and recognise how a WHERE clause is formatted and works within SQL (SQL format closely matches what is expected in the WhereCondition parameter that we're talking about here from your code.)? If not then we have to look at some very basic work with you, but as you'll already have seen, we have many willing helpers who can do that as long as they realise it's necessary.

                    I suspect once we stop following you round in circles we can reach a solution that not only works for you, but also one that you'll understand and be able to use in future.

                    Best of luck & welcome to Bytes.com.
                    Last edited by NeoPa; Jul 20 '21, 10:39 PM.

                    Comment

                    Working...