Results 1 to 2 of 2
  1. #1
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265

    Setting a default value of 0 in a query

    I have a table called "Paid" with a field called "hoursPaid." Then I query this table with a query called "qryPaid." In this query, I apply a SUM aggregate function.



    I have a second query called "qryCTPaidHours" which queries the query called "qryPaid."

    So here is what I have so far: qryCTPaidHours -->qryPaid --> Paid (table)


    In "qryCTPaidHours" in design view, I have a field called "SumOfhoursPaid" which is ultimately derived from the field called "hoursPaid" in the table called "Paid." But in Datasheet View, this same field shows up as "hoursPaid." In this field, I want to add a default value of zero.

    I found some code which can supposedly do this but I can't get it to work. Is it because I have to use a query instead of a table after the FROM statement (see below in green)?



    Here is the code I am trying:

    Code:
    declare @static_number
    set @static_number = 0
     
    select @static_number as MyZero, SumOfhoursPaid from qryPaid
     
     
    SELECT ClickTime.billingAcct, billingAccounts.Exostar, ClickTime.weekEnding, ClickTime.ClickTimeHours, qryPaid.SumOfhoursPaid, [ClickTimeHours]-[SumofHoursPaid] AS unPaid
    FROM billingAccounts INNER JOIN (ClickTime LEFT JOIN qryPaid ON (ClickTime.weekEnding = qryPaid.weekEnding) AND (ClickTime.billingAcct = qryPaid.billingAcct)) ON billingAccounts.billingAccount = ClickTime.billingAcct;

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Where are you putting this code? That isn't VBA.

    I don't see hoursPaid field in that SQL.

    If you want 0 to show when field is Null, use Nz() function

    Nz(hoursPaid,0)
    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.

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

Similar Threads

  1. Setting default value to zero in form box?
    By dekhelia in forum Forms
    Replies: 6
    Last Post: 10-17-2013, 08:53 AM
  2. Automaticly Setting Default Value
    By swicklund in forum Forms
    Replies: 5
    Last Post: 06-17-2013, 08:08 AM
  3. Replies: 6
    Last Post: 10-20-2012, 04:45 PM
  4. Setting default vaulue?
    By djclntn in forum Forms
    Replies: 17
    Last Post: 04-12-2012, 11:20 PM
  5. Replies: 1
    Last Post: 11-01-2010, 06:59 PM

Tags for this Thread

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