Results 1 to 5 of 5
  1. #1
    endri81 is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    26

    Query runs fine but report doesnt work


    Hi
    When I run query :

    SELECT datepart("q",[Data e fillimit te tremujorit]) & year([Data e fillimit te tremujorit]) AS PeriodQuarter, clng(IIf(left(PeriodQuarter,1) In (2,3,4),year([Data e fillimit te tremujorit]),year([Data e fillimit te tremujorit])-1)) AS FiscalYear, *
    FROM Konsumi_Disaperiudha1_Gimi;

    it runs fine and shows table result
    but when I try to build a report by using this query I get message:

    "The wizard is unable to open your query in Datasheet view, possibly because another user has a source table open in exclusive mode. Your query will be opened in design view"

    and if I click Ok and try to preview report I get
    Invalid use of Null

    I see that in Dataview there are some #ERROR fields as shown in picture attached.
    Maybe this is the cause.
    How to get rid of this issues?

    Please help
    Attached Thumbnails Attached Thumbnails pic1.jpg  

  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Wherever you reference field [Data e fillimit te tremujorit] that is null, you will get an error in the calculation. You will need to tell Access what to do when it encounters a null field. This is accomplished using the NZ function. Look at this for explanation of NZ

    http://www.techonthenet.com/access/f...dvanced/nz.php

    You will have to wrap any calculation of this field in an NZ function.


  3. #3
    endri81 is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    26
    Thx this seems interesting and possible solution but not working for my query :

    SELECT datepart("q",[Data e fillimit te tremujorit]) & year([Data e fillimit te tremujorit]) AS PeriodQuarter, clng(IIf(left(PeriodQuarter,1) In (2,3,4),year([Data e fillimit te tremujorit]),year([Data e fillimit te tremujorit])-1)) AS FiscalYear, *
    FROM Konsumi_Disaperiudha1_Gimi;

    Maybe I am making it wrong ,can you please help on modification of the specific query?
    Regards


  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    If the field is empty that you are trying to use as a base for the calculation, what do you want Access to do? I can help you but you need to address that issue first. What value do you want if the the field is null?

    Code:
    SELECT datepart("q",[Data e fillimit te tremujorit]) & year([Data e fillimit te tremujorit]) AS PeriodQuarter, clng(IIf(left(PeriodQuarter,1) In (2,3,4),year([Data e fillimit te tremujorit]),year(NZ([Data e fillimit te tremujorit]),Need Value Here)-1)) AS FiscalYear, *
    FROM Konsumi_Disaperiudha1_Gimi;
    
    


    Without the NZ function, you will continue to get errors as Access doesn't know what to do with the Null field. It cannot do a calculation as you are asking on a Null.

  5. #5
    endri81 is offline Novice
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    26
    Thx for the very fast answer
    I changed value Need Value Here with "0" but still giving error Syntax Error missing operator??
    What to do?
    Regards

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

Similar Threads

  1. Replies: 2
    Last Post: 09-08-2011, 11:14 AM
  2. Help I dunno y it doesnt work
    By zaza123 in forum Programming
    Replies: 7
    Last Post: 07-03-2011, 06:43 PM
  3. Help fine tuning mail merge from switchboard
    By saythein in forum Access
    Replies: 1
    Last Post: 09-06-2010, 01:14 AM
  4. Replies: 1
    Last Post: 08-17-2010, 11:24 PM
  5. Form that runs query and creates reports
    By Valeda in forum Forms
    Replies: 2
    Last Post: 05-04-2006, 07:01 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