Results 1 to 9 of 9

Thread: ADO - EXCEL problem

  1. #1

    Thread Starter
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Exclamation ADO - EXCEL problem

    Hi all,

    I am creating very simple database in excel and I would like to implement simple searching mechanism using ADO.

    To achieve this aim I wrote such a piece of code:

    VB Code:
    1. Dim search_result As String
    2.  
    3. search_result = "'%" & frmsearch.TextBox1.Text & "%'"
    4.  
    5. Dim rec As ADODB.Recordset
    6. Dim conn As ADODB.Connection
    7.  
    8. Set conn = New ADODB.Connection
    9.  
    10. conn.Provider = "Microsoft ole db provider for odbc drivers"
    11. conn.ConnectionString = "driver={microsoft excel driver (*.xls)};dbq=" & _
    12. ThisWorkbook.Path & "\film_catalog.xls;"
    13.  
    14. conn.Open
    15.  
    16. Set rec = New ADODB.Recordset
    17. rec.CursorLocation = adUseClient
    18. rec.Open "select * from [catalog$] where category like " & (search_result), conn, adOpenDynamic, adLockOptimistic

    but I have such a problem: excel doesn't ignore size of chars.
    for exmaple: when I want to search a film category horror so I type horror but in database I have Horror so that I get empty recordset.

    I was trying to use Option Compare Text but it doesn't work,

    How can I make excel ignoring char's size???

    please help

    thx in advance for your help

    regards,
    sweet_dreams

  2. #2
    New Member
    Join Date
    Apr 2004
    Posts
    12

    Re: ADO - EXCEL problem

    I couldn't duplicate this behavior. What versions are you using?

    Anyways, one option might be to convert everything to uppercase:

    VB Code:
    1. search_result = "'%" & UCase(frmsearch.TextBox1.Text) & "%'"
    2.  
    3. rec.Open "select * from [catalog$] where UCase(category) like " & (search_result), conn, adOpenDynamic, adLockOptimistic


    HTH

  3. #3
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: ADO - EXCEL problem

    sweet dreams:

    Perhaps this Web site would help you?

    http://www.excel-vba.com/e-database-functions.htm

  4. #4

    Thread Starter
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: ADO - EXCEL problem

    Hi guys,

    Thanks a lot for your reply but unfortunatelly your advices didn't help.
    Can anybody help me with this problem???

    regards,

    sweet_dreams

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: ADO - EXCEL problem

    Post #2's code should work for you. Did you get any errors and what were the results of the search?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: ADO - EXCEL problem

    RobDog888,

    I am sorry post #2's code works perfect.

    But now I am trying to do it another way. Instead of
    UCase(category)
    I would like to use variable. I mean:

    rec.Open "select * from [catalog$] where " & UCase(variable_category) & " like " & (search_result), conn, adOpenDynamic, adLockOptimistic
    and in this case this code doesn't work. excel doesn't ignore char's size.

    what should I do now???

    please help

    regards,
    sweet_dreams

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: ADO - EXCEL problem

    Instead of doing it in-line try setting the variable to ucase before hand.
    VB Code:
    1. Dim variable_category as string
    2. variable_category = "SomeThing"
    3. variable_category = UCase$(variable_category)
    4. rec.Open "select * from [catalog$] where " & variable_category & " like " & (search_result), conn, adOpenDynamic, adLockOptimistic
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Addicted Member sweet_dreams's Avatar
    Join Date
    Apr 2005
    Location
    Poland, Lodz
    Posts
    189

    Re: ADO - EXCEL problem

    unfortunately it also doesn't work

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: ADO - EXCEL problem

    Are youtring to search numeric and textual data types?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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