Searching a query in vba

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

    Searching a query in vba

    Im trying to get a form to search a query using SQL for an ID. The sql which im using is.
    SELECT tblCustomer.Cus tomerName, tblCustomer.Cus tomerID, tblOrder.OrderI D
    FROM tblCustomer INNER JOIN tblOrder ON tblCustomer.Cus tomerID = tblOrder.Custom erID
    WHERE (((tblCustomer. CustomerName)=[enter name]));

    Im trying to open that query and search for a value where the tickbox has been selected.

    [CODE=vb]Private Sub Command5_Click( )
    Dim rstCustomer As ADODB.Recordset
    Dim conDatabase As ADODB.Connectio n
    Dim strSQL As String
    Dim strConditions As String


    Set conDatabase = CurrentProject. Connection

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


    MsgBox (strSQL)
    DoCmd.OpenQuery "QryFindOrd ers"

    End Sub[/CODE]

    OK ive got it to open the query but its not searching for the value.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Does the query return any data when executed in the back end with the input ?

    Comment

    • Clant1
      New Member
      • Feb 2008
      • 13

      #3
      it does when i enter the value to search but thats what the text box is ment to be doing

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Try to use the following code.

        [code=vb]strSQL = "SELECT * FROM QryFindOrders where CustomerName = '" & Text1 &"'"[/code]

        Comment

        • Clant1
          New Member
          • Feb 2008
          • 13

          #5
          Originally posted by debasisdas
          Try to use the following code.

          [code=vb]strSQL = "SELECT * FROM QryFindOrders where CustomerName = '" & Text1 &"'"[/code]
          thanks alot that works

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            You are most welcome .

            Comment

            Working...