Multiple selection from SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Clant1
    New Member
    • Feb 2008
    • 13

    Multiple selection from SQL

    Im now trying to make my sql select two or more different values and display them with a report using access.

    Code:
     strSQL = "SELECT * FROM tblcustomer where CustomerName = '" & Text1 & "'
    What ive tried so far is using a Or but it didnt work at all.
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #2
    Code:
     strSQL = "SELECT * FROM tblcustomer where CustomerName = " & "'" & Text1.text & "'"
    Try this

    Comment

    • Clant1
      New Member
      • Feb 2008
      • 13

      #3
      Originally posted by jamesd0142
      Code:
       strSQL = "SELECT * FROM tblcustomer where CustomerName = " & "'" & Text1.text & "'"
      Try this
      Cheers got that working now but for some reason it tries to print the report that its looking at everytime now and theres not command telling it to print anywhere in my code

      Comment

      • jamesd0142
        Contributor
        • Sep 2007
        • 471

        #4
        Originally posted by Clant1
        Cheers got that working now but for some reason it tries to print the report that its looking at everytime now and theres not command telling it to print anywhere in my code
        Im lost now :), Post your code and i'm sure some1 can point you in the rightdirection.

        James

        Comment

        • Clant1
          New Member
          • Feb 2008
          • 13

          #5
          ok.
          The problem is in the second if statement for some reason when it looks at the report it wants to print it off. i think its something to do with teh strSQL2 value becuase it was when i added that it started breaking. The report asked for a parameter value when it loads as well which it shouldnt do becuase the SQL tells it not to but when it opens it also tries to print it as well. The report is a bad one which runs fine on its own and doesnt try to print anything else off.
          [code=vb]
          Private Sub Command15_Click ()

          Dim rstCustomer As ADODB.Recordset
          Dim conDatabase As ADODB.Connectio n
          Dim strSQL As String
          Dim strConditions As String
          Dim strSQL2 As String

          Set conDatabase = CurrentProject. Connection

          If Check10.Value = True Then
          strSQL = "SELECT * FROM tblcustomer where CustomerName = '" & Text1 & "'"

          MsgBox (strSQL)
          DoCmd.OpenForm "tblcustome r", , strSQL

          'strSQL = strSQL & " OR '" & variable & "'" sql template


          End If


          If Check12.Value = True Then
          strSQL2 = "SELECT * FROM tblorders where orderID = '" & Text3 & "'"
          MsgBox strSQL2
          DoCmd.OpenRepor t "tblorder", , strSQL2


          End If

          End Sub
          [/code]

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Hi,

            I guess your Order Report is Based on a Query Object, which in turn needs a Parameter. Just check it, and Remove if any Parameters are there in the Query Object....

            Regards
            Veena

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              The view property of the OpenReport method is your problem.

              Originally posted by Access help
              View Optional AcView. The view to apply to the specified report.

              AcView can be one of these AcView constants.
              acViewDesign
              acViewNormal default Prints the report immediately.
              acViewPivotChar t Not supported.
              acViewPivotTabl e Not supported.
              acViewPreview

              Comment

              • Clant1
                New Member
                • Feb 2008
                • 13

                #8
                set it to preview fiddled alot with this guy from irc as well and got it working thanks alot again guys

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Glad we could help. :)

                  Comment

                  Working...