Results 1 to 12 of 12

Thread: Database Search Error

  1. #1

    Thread Starter
    Lively Member chongo 2002's Avatar
    Join Date
    Apr 2000
    Posts
    106
    Dim My_Query As String

    My_Query = cbosearch & " " & Cbo_Operator & " " & txtsearch.Text & "'"

    Data1.RecordSource = "SELECT * FROM General WHERE " & My_Query

    Data1.Refresh

    Data1.Recordset.MoveLast: Data1.Recordset.MoveFirst
    MsgBox Data1.Recordset.RecordCount & " matches found."
    Exit Sub

    Does anyone see a syntax error?

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Posts
    114

    error

    What is the error you are getting?

  3. #3

    Thread Starter
    Lively Member chongo 2002's Avatar
    Join Date
    Apr 2000
    Posts
    106
    Error 3022 Syntax error in from statement.

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Posts
    114

    error

    What is the value of each of these when you get the error?

    cbosearch
    Cbo_Operator
    txtsearch.Text

  5. #5

    Thread Starter
    Lively Member chongo 2002's Avatar
    Join Date
    Apr 2000
    Posts
    106
    cbosearch is the name of a databse field like - Name and txt search is the name you are searching for the other combo box I deleted but set the value to Like.

  6. #6
    Lively Member
    Join Date
    Aug 2000
    Posts
    114
    It looks like you don't have your other single quote in from the the txtSearch.Text. You should have this and only this for alpa fields. If it is numeric take out the single quotes around txtSearch.text

    My_Query = cbosearch & " " & Cbo_Operator & " '" & txtsearch.Text & "'"



  7. #7
    Lively Member
    Join Date
    Aug 2000
    Posts
    114
    I said from txtSearch.text, what I meant was in Front of txtSearch.text you need the other single quote

  8. #8

    Thread Starter
    Lively Member chongo 2002's Avatar
    Join Date
    Apr 2000
    Posts
    106
    It is still giving the same error. I am just trying to search my database for a name or number from a textbox and display the results of the whole row in other textboxes.

  9. #9
    Fanatic Member spud's Avatar
    Join Date
    Aug 2000
    Location
    Munster (Germany)
    Posts
    542

    Wink

    Try this

    Dim My_Query As String
    'You missed out this (')
    My_Query = cbosearch & " " & Cbo_Operator & " '" & txtsearch.Text & "'"

    Data1.RecordSource = "SELECT * FROM General WHERE " & My_Query

    Data1.Refresh

    Data1.Recordset.MoveLast: Data1.Recordset.MoveFirst
    MsgBox Data1.Recordset.RecordCount & " matches found."
    Exit Sub

    You missed out (') in your code

    Hope this helps

    Spud

  10. #10

    Thread Starter
    Lively Member chongo 2002's Avatar
    Join Date
    Apr 2000
    Posts
    106
    It still gives me the error but i think something else somewhere else in the code is causing the error, not the actual search part. But there are to many lines to post all the code.

    [Edited by chongo 2002 on 09-08-2000 at 09:27 PM]

  11. #11

    Thread Starter
    Lively Member chongo 2002's Avatar
    Join Date
    Apr 2000
    Posts
    106
    The General needs to be [General] for anyone who has this same problem.

  12. #12
    Member
    Join Date
    May 2000
    Location
    Sweden
    Posts
    50

    Smile You are missing something...

    Try:

    Data1.RecordSource = "SELECT * FROM General WHERE Myfield = " & My_Query

    Wolf

    VB6 SP5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width