Results 1 to 5 of 5
  1. #1
    RayMilhon is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,068

    ADODB Recordset behaving strangely

    I have the following function in an MS Access Database

    Public Function Get_Status(ByRef str_Status As String) As Long
    Dim rs As New ADODB.Recordset, strsql
    Select Case str_Status
    Case Is = "OPTED-OUT", Is = "OPT-OUT"
    str_Status = "OPTED OUT"
    Case Is = "TERMED."
    str_Status = "TERMED"
    End Select
    strsql = "Select DISPOSITIONID From tbl_Dispositions Where DISPOSITION_DESC Like ""*" & str_Status & "*"""
    rs.Open strsql, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
    If Not rs.EOF Then
    Get_Status = rs!DispositionID
    End If
    rs.Close


    Set rs = Nothing

    End Function

    The purpose of this function is that we are taking an Excel Spreadsheet and converting it to an Access DB. One of the Fields in the spreadsheet is Disposition which is in Text. I've created a Dispositions Table with a PK and Description. When the spreadsheet is converted to a table the Status Field is updated with the DispositionID. The SQL that is built above ends up looking like

    Select DispositionID From Dispositions Where Dispositions_Desc Like "*Termed*"

    If I copy that SQL into a Query I get the result 1 row with DispositionID = 2 which is correct. However when I call the function from my update Query I get 0 rows. Same query. 1 from the Query Designer which gives the correct value and 1 in code which doesn't.

    Any Ideas why?

    This is access 2010 by the way

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    ADO wants % as a wildcard instead of *.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RayMilhon is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,068
    Doh! had my stupid moment of the day.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No stupidity involved; a lot of people don't know about it. JET and DAO want *, but ADO wants the %. You'd think they'd be consistent.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    RayMilhon is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,068
    In my case it was a stupid moment as I already knew that. Was just in a hurry and mixed up the * and %

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 08-23-2012, 12:28 AM
  2. bind field to adodb.recordset field
    By gem1204 in forum Access
    Replies: 7
    Last Post: 04-26-2012, 01:07 PM
  3. Recordset not behaving as expected
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 02-15-2011, 04:25 PM
  4. intellisense not behaving
    By avianrand in forum Programming
    Replies: 3
    Last Post: 06-18-2010, 04:59 PM
  5. Replies: 0
    Last Post: 10-21-2008, 10:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums