|
-
Jul 22nd, 2003, 08:19 PM
#1
Thread Starter
New Member
Simple Search ADO
I am trying to search an Access database using an ADO data control, and am having problems. I have the following code:
Dim NewSearch As String
NewSearch = InputBox("Enter User Login", "Search")
If NewSearch = ("") Then Exit Sub
adoLogin.RecordSource = "SELECT * FROM Logins WHERE Login LIKE '%" & NewSearch & " % '"
adoLogin.Refresh
It says I have an error in my FROM statement, and I can't see it at this point. I have tried several ways. Someone please help
-
Jul 22nd, 2003, 09:30 PM
#2
well, for starters, use * instead of %..... Access used the * wildcard, instead of the usual % in SQL.... also, it looks like there's a space before the last wildcard.... which may cause problems...
-
Jul 22nd, 2003, 11:02 PM
#3
Hyperactive Member
techgnome is correct. also there should be another ' before the final * (assuming it is a string)
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
Jul 23rd, 2003, 03:11 PM
#4
Thread Starter
New Member
Okay, thanks for the replies. So I made the changes to the line as suggested and I have this, and still the same error:
Dim NewSearch As String
NewSearch = InputBox("Enter User Login", "Search")
If NewSearch = ("") Then Exit Sub
adoLogin.RecordSource = "SELECT * FROM Logins WHERE Login LIKE '*" & NewSearch & "'* '"
adoLogin.Refresh
It's all blurry to me at this point. Please help
-
Jul 23rd, 2003, 03:21 PM
#5
No, stingrae got it wrong.... there SHOULDN'T be ' before the *......
the * needs to be inside the quite identifiers ( that's the ' )
it should read like this:
VB Code:
adoLogin.RecordSource = "SELECT * FROM Logins WHERE Login LIKE '*" & NewSearch & "*'"
-
Jul 23rd, 2003, 07:09 PM
#6
Hyperactive Member
oops. sorry, you're right. i meant after the *!
lack of coffee......
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
Jul 24th, 2003, 06:20 AM
#7
Thread Starter
New Member
-
Jul 24th, 2003, 08:46 AM
#8
hmmmmm
I have to admit, I'm a bit stumped.... the only thing that comes to mind is if Login or Logins is a reserved word in Access.... try putting [] around Logins and Login and see if that helps....
adoLogin.RecordSource = "SELECT * FROM [Logins] WHERE [Login] LIKE '*" & NewSearch & "*'"
Something else I notices, Access is particular about having a ; at the end of SQL statements.....
adoLogin.RecordSource = "SELECT * FROM [Logins] WHERE [Login] LIKE '*" & NewSearch & "*';"
-
Jul 24th, 2003, 06:59 PM
#9
Hyperactive Member
one thing i often do to test my SQL, when i build it in VB and it fails, is to copy and paste it into Access.
i.e. open access, and create a new query, select SQL view and paste the completed SQL statement in there (normally i do a debug.print just before the rs.open and take that).
if it works in Access, then there's something wrong with the way the connection is setup, but if it fails in access, it will give you a better message.
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
Jul 25th, 2003, 08:06 AM
#10
Lively Member
Try this one.
Depending on how many search criteria do you have, split the SQL code to be like this:-
VB Code:
Private Sub Search()
Dim myStr(1 to 3) as String
'Connect to a Database using code, not ADO.
Dim CNN as new ADODB.Connection
Dim CNNStr as String
Dim rstRecord as New ADODB.Recordset
CNNStr="Provider=Microsoft.Jet.OLEDB.4.0"; _
"Data Source= App.Path \Database.mdb"
CNN.Open CNNStr
myStr1 Like "*" & "txtText" & "*"
myStr2 Like "*" & "txtText" & "*"
myStr3 Like "*" & "txtText" & "*"
'Please check, if txtText is numeric, you might just have to add Like '"*" & "txtText" & "*"'
rstRecord.Open,"SELECT * FROM [Logins] WHERE myStr1 & myStr2 & myStr3, CNN 'Please verify my syntax code
Set DataGrid.DataSource=rstRecord
End Sub
I hope you come right
Wizard
SA
-
Aug 1st, 2003, 08:29 AM
#11
Thread Starter
New Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|