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

    Same query different locations different results

    Why would a query (a simple one at that) generate different results when executed in VBA as opposed to the query builder in Access 2010.

    The query is

    Code:
    SELECT avg(dbo_V_iC_HVVMG_MemberRiskScore.CurrentYearRAF) AS RAFScore 
    FROM dbo_V_iC_HVVMG_MemberRiskScore 
    Where dbo_V_iC_HVVMG_MemberRiskScore.PCPLastName like "SMIT*" and dbo_v_ic_hvvmg_memberriskscore.pcpfirstname like "JOHN*";
    If run in the query builder I get the expected result 1.559


    When run in code I get Null.

    yes dbo_v_ic_hvvmg_memberriskscore is a linked SQL Server 2008 R2 table.

    It's running in VBA because the report is grouped by PCP and is run for each of the PCP's. This particular query populates a single field in the group footer. There are 2 other fields in the footer that perform similarly. 1 for Total PCP membership and 1 for the total number of Wellness Surveys done by the PCP. Both of those work just fine. This one worked but the method of retrieving the score took hours to run. I have access to a datawarehouse where the scores were already calculated so I revised the report to look there speeding up the report into a few minutes. (hopefully if I can get it to actually run correctly)

    any help is appreciated.

  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
    What does the code-based version look like? At a guess, the SQL isn't coming out like you expect. You can use this to test:

    BaldyWeb-Immediate window

    Oh, and if you're using ADO, the wildcard needs to be %.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Are you using this query to open ADO RecordSet?

    I encountered this when constructing query in VBA that has wildcard. I was so frustrated I redesigned the query to eliminate wildcard. I later learned ADO uses different wildcards. Review http://www.techrepublic.com/article/...a-expressions/

    Why are you using name as criteria? You want all John* Smit* records, even if more than one person named John* Smit*?

    Why do you need query to get this aggregate calc? Is the raw data in the report RecordSource? Can't just use Avg() in textbox in report footer?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    June7 No the raw data for this field is in a different database and tables. Also the Source for this report is the members that need a certain examination done and the RAF Score is based on a different dataset. Only need the average of 1 field by Provider for this report. Unfortunately the dataset for this RAF Score does not have the same data elements and the Provider name is the only thing in common. Although I have to use only the left 4 of each as they are not exactly the same. The report data has the name as "SMITH M.D., JOHN
    and the RAF Score has "Smith" in 1 column, "JOHN" in another column and "MD" in a third. None of our providers have a last name shorter than 4 characters so that is why I used that. I do use ADO and changing the * to % helped but there still quite a few that are coming through as 0 when the data is there and if I run the query in the query builder it returns the correct data. In VBA it's null.

  5. #5
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Thanks Paul, I'd forgotten the % for ADO. It helped but still not 100% I do get the data for some but not for all. still working on it.

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

Similar Threads

  1. Trusted locations
    By kcmiuser in forum Security
    Replies: 1
    Last Post: 08-14-2013, 09:48 AM
  2. Replies: 5
    Last Post: 05-21-2013, 02:21 PM
  3. Replies: 3
    Last Post: 05-02-2013, 10:36 AM
  4. Replies: 6
    Last Post: 05-14-2012, 07:24 AM
  5. Replies: 0
    Last Post: 01-26-2011, 05: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