Results 1 to 10 of 10
  1. #1
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071

    Recordset Failed Error

    I have a report in MS Access 2010 that uses some VBA Code to rank certain Accumulations in my Report. This is the error I'm getting

    Click image for larger version. 

Name:	Recordset_failed.jpg 
Views:	17 
Size:	27.9 KB 
ID:	28217

    This is the VBA producing the error

    Code:
            strtest = "Select star from tbl_stars Where submeasure = """ & "MRP" & """ and " & _
            CInt(Val(Me.txtbmi3) * 100) & " Between low and high "
            rsstars.Open strtest, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
            overallstar(1) = rsstars!star
            PartC(1) = rsstars!star
            Me.txtbmi4 = fStars(rsstars!star)
            rsstars.Close
    The reason I'm having trouble with this is that in my report I have 14 different groupings all 14 run the same code. The only thing that changes is the text between "Where submeasure = """ and """ and ". In the sample above it's the "MRP". The code works 13 out of 14 times and only fails for this one section.

    Here's the SQL for one that works



    Select star from tbl_stars Where submeasure = "ABA - BMI within measure year or prior year" and 98 Between low and high

    the result should be 5 and is

    Here's the SQL for the one that doesn't

    Select star from IStar_Matrix Where submeasurecode = "MRP" and 1 Between beg and end

    the result should be 1 but I get the above error instead. If I run it in Query Analyzer it gives me the expected result. Any thoughts?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is there a [submeasurecode] field? Does it contain at least 1 record with "MRP" as a value?

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    have you tried a query, not sql?

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    It may be because "End" is a reserved word and should not be used as a field (or control) name. Try changing it to something you know is not a reserved word.

  5. #5
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Yes there is a submeasurecode field as I stated the same query works 13 times out of 14 It only doesn't work when submeasure code is = "MRP" and yes there are records that equal that. The query works fine in Query Analyzer just won't work in code.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,815
    some thoughts:
    - for one case, maybe Val is not returning an expected number (in which case, it would return 0)
    - I would print the sql and check it, but I also favor single quotes over doubling up on doubles.
    Code:
    strtest = "Select star from tbl_stars Where submeasure = '" & "MRP" & "'" and " & _
    CInt(Val(Me.txtbmi3) * 100) & " Between low and high"
    debug.print strtest
    You could restrict the print to when a certain criteria value (MRP?) is being used, or just scan 14 outputs in the immediate window. If nothing obvious shows, I'd test the variables and expressions in the immediate window in break mode, such as
    ?CInt(Val(Me.txtbmi3) * 100)
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    I've checked the Value of Cint(Val(me.txtbmi3) * 100) = 1.44 low is 0 and high is 21.00 So the Query in Query Analyzer returns the value 1 as it's supposed to. It's just in the VBA Code I get the error.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Hmm...there is always a chance there is some sort of corruption. You might try *importing* everything into a fresh new db and see if the issue follows.
    https://btabdevelopment.com/how-to-i...-new-mdb-file/
    This process tend to leave any corruption behind. Just a thought.

  9. #9
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,815
    Quote Originally Posted by RayMilhon View Post
    I've checked the Value of Cint(Val(me.txtbmi3) * 100) = 1.44 low is 0 and high is 21.00 So the Query in Query Analyzer returns the value 1 as it's supposed to. It's just in the VBA Code I get the error.
    But does the entire sql statement look right when it's debugged.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The only thing that changes is the text between "Where submeasure = """ and """ and ".
    But that is not the only thing that changes, from what you've shown. The SQL that doesn't work is selecting the field 'star' from a different table (IStar_Matrix vs. tblStars), uses a different field following WHERE (submeasurecode vs. submeasure), and uses different fields in the comparison (beg & end vs. low & high).

    So, your two SQL statements are actually completely different, and there could be any number of things wrong.

    It only doesn't work when submeasure code is = "MRP"
    Is it submeasurecode (no space) or submeasure code (with a space), in which case use [submeasure code]?

    Can you post a list of the fields in each table (IStar_Matrix & tblStars)? It might help us narrow down the problem.

    I can't see why it would make a difference, but you could try DAO instead of ADO:

    Dim rsstars as recordset
    set rsstars = currentdb.openrecordset(sql)

    (where using a field called 'end' DOES work)
    Last edited by John_G; 04-10-2017 at 09:30 PM. Reason: Add more text

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

Similar Threads

  1. Replies: 4
    Last Post: 08-12-2014, 08:47 AM
  2. Event failed to run error!!
    By Blakey129 in forum Access
    Replies: 4
    Last Post: 11-25-2013, 04:51 PM
  3. Export Data w/FSO - Open object recordset failed
    By JayZoll in forum Programming
    Replies: 1
    Last Post: 11-12-2012, 01:38 PM
  4. ODBC -- Call Failed error
    By Coffee in forum Access
    Replies: 3
    Last Post: 07-08-2011, 10:34 AM
  5. Action Failed -Error Number: 2950
    By Cindy in forum Access
    Replies: 5
    Last Post: 07-07-2010, 11:51 AM

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