PDA

Click to See Complete Forum and Search --> : Database Search Error


chongo 2002
Sep 6th, 2000, 06:26 PM
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?

thedee23
Sep 6th, 2000, 06:52 PM
What is the error you are getting?

chongo 2002
Sep 6th, 2000, 08:04 PM
Error 3022 Syntax error in from statement.

thedee23
Sep 6th, 2000, 08:31 PM
What is the value of each of these when you get the error?

cbosearch
Cbo_Operator
txtsearch.Text

chongo 2002
Sep 7th, 2000, 01:56 PM
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.

thedee23
Sep 7th, 2000, 02:08 PM
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 & "'"

thedee23
Sep 7th, 2000, 02:09 PM
I said from txtSearch.text, what I meant was in Front of txtSearch.text you need the other single quote

chongo 2002
Sep 7th, 2000, 03:00 PM
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.

spud
Sep 8th, 2000, 06:15 PM
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

chongo 2002
Sep 8th, 2000, 08:10 PM
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]

chongo 2002
Sep 19th, 2000, 09:21 PM
The General needs to be [General] for anyone who has this same problem.

Wolf
Sep 19th, 2000, 09:55 PM
Try:

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