Results 1 to 11 of 11

Thread: Simple Search ADO

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Location
    Texas
    Posts
    4

    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
    Always Confused

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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...
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Location
    Texas
    Posts
    4
    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
    Always Confused

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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:
    1. adoLogin.RecordSource = "SELECT * FROM Logins WHERE Login LIKE '*" & NewSearch & "*'"
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401
    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Location
    Texas
    Posts
    4
    Okay, so now I have

    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


    And still have the same error. Please help
    Always Confused

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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 & "*';"
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401
    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

  10. #10
    Lively Member
    Join Date
    Dec 2001
    Location
    South Africa
    Posts
    88
    Try this one.

    Depending on how many search criteria do you have, split the SQL code to be like this:-

    VB Code:
    1. Private Sub Search()
    2. Dim myStr(1 to 3) as String
    3.  
    4. 'Connect to a Database using code, not ADO.
    5. Dim CNN as new ADODB.Connection
    6. Dim CNNStr as String
    7. Dim rstRecord as New ADODB.Recordset
    8.  
    9. CNNStr="Provider=Microsoft.Jet.OLEDB.4.0"; _
    10. "Data Source= App.Path \Database.mdb"
    11.  
    12. CNN.Open CNNStr
    13.  
    14. myStr1 Like "*" & "txtText" & "*"
    15. myStr2 Like "*" & "txtText" & "*"
    16. myStr3 Like "*" & "txtText" & "*"
    17.  
    18. 'Please check, if txtText is numeric, you might just have to add Like '"*" & "txtText" & "*"'
    19.  
    20.  
    21. rstRecord.Open,"SELECT * FROM [Logins] WHERE myStr1 & myStr2 & myStr3, CNN     'Please verify my syntax code
    22.  
    23. Set DataGrid.DataSource=rstRecord
    24.  
    25. End Sub

    I hope you come right

    Wizard
    SA







  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Location
    Texas
    Posts
    4

    Simple Search ADO RESOLVED :)

    Thanks for the help, I finally got it
    Always Confused

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