1. Attachments are working again! Check out this thread for more details and to report any other bugs.

Microst Access Help

Discussion in 'Fred's House of Pancakes' started by TonyPSchaefer, Dec 17, 2007.

  1. TonyPSchaefer

    TonyPSchaefer Your Friendly Moderator
    Staff Member

    Joined:
    May 11, 2004
    14,816
    2,498
    66
    Location:
    Far-North Chicagoland
    Vehicle:
    2017 Prius Prime
    Model:
    Prime Advanced
    I'm looking for some assistance with a Microsoft Access database that I'm creating. Actually, it's the form I need help with.

    The purpose of the form is to enter labor estimates for the multiple projects I work on. The form shows all months of fiscal years 2008 and 2009. Under each month label is a field in which I enter the estimated number of days I expect to work on the project.

    Here's the problem: in order for the totals to calculate in the far-right, all the fields have to be entered with a number. This means that the months during which I will not be working on the project must have a "0". In my opinion, this is crowded and clunky and I would rather just have blanks. See attachment. In the top row (Project Manager) you will see that there are two blank fields keeping the 'Totals' field from calculating. The Developer row, however, is populated with zeros and the total calculates.

    This database is a next generation version of an Excel spreadsheet I have been using in which I can leave cells blank and the totals still calculate. I and my coworkers like that much better because you can just glance and know when the work is being done. With the zeros, you have to scrutinize each cell to determine if it's a number or a zero.

    Subsequently, the reports generated form the database are also filled with zeros and crowded.

    Who can help me suppress the zeros but still calculate the totals?
     

    Attached Files:

  2. eagle33199

    eagle33199 Platinum Member

    Joined:
    Mar 2, 2006
    5,122
    268
    0
    Location:
    Minnesota
    Vehicle:
    2015 Prius v wagon
    Model:
    Two
    Tony - it's been a while since i've used Access, but i'm pretty good with DB's in general. It sounds like what you need to do is something like an Oracle DECODE function for the cell that does the totals. The basic idea is that if you're doing the sum and it tries to sum a null value it explodes. So instead you do a decode of the value. In SQL, you go from this:

    SELECT SUM(column1) FROM table1

    to this:

    SELECT SUM(DECODE(column1, null, 0, column1)) FROM table1


    The decode function (in Oracle) basically works like this: the first variable is the column you want to decode. After that you can put as many 2-value pairs as you want, where the first is the value you want to change (in this case null, or nothing) and the second is the value you want to change it to (0). the final one is the default value if it doesn't match any of the previous values.

    So in oracle, DECODE(column1, null, 0, column1) would change all null values to a 0 for the resulting set, leaving everything else the same.

    from http://eis.bris.ac.uk/~ccmjs/ora_sql.htm, we see the equivalent for Access databases: iif(expression, value if true, value if false)

    So i would guess the query for an Access DB would look something like:

    SELECT sum(iif(isnull(column1), 0, column1)) FROM table1
     
  3. TimBikes

    TimBikes New Member

    Joined:
    Sep 27, 2005
    2,492
    245
    0
    Location:
    WA
    Vehicle:
    2005 Prius
    Tony - it's been a while since I've used Access too, so I may be talking out of my arse - but maybe you can use a field input mask? That way blank cells would only have a "__" as an input field -- perhaps. Input mask can be specified in the table set-up for a specific field.
     
  4. TonyPSchaefer

    TonyPSchaefer Your Friendly Moderator
    Staff Member

    Joined:
    May 11, 2004
    14,816
    2,498
    66
    Location:
    Far-North Chicagoland
    Vehicle:
    2017 Prius Prime
    Model:
    Prime Advanced
    Eagle,
    I was originally thinking along these lines. However, the thought of having to perform that function for all 24 fields and then having to do it a total of four times was just overwhelming.

    The screen shot attachment above shows where I enter the estimated labor for the project. What you don't see is that on the next tab of the form, you can enter the actual numbers. So there are 24 months for the PM to enter estimates and 24 for actuals. Then there are 24 for the Developer's estimates and 24 more for actuals.

    But seriously, it must be a really good idea because I was thinking along those lines. :D

    And Tim, I couldn't get that to work to my satisfaction. I seriously think that it's attempting to perform math on whatever is in the cell. And with the default mask, it attempts to do math on the '-' or the '_' or whatever mask I tried.
     
  5. TimBikes

    TimBikes New Member

    Joined:
    Sep 27, 2005
    2,492
    245
    0
    Location:
    WA
    Vehicle:
    2005 Prius
    I'd use Excel if I could get away with it! ;)
     
  6. TheAnnoyingOne

    TheAnnoyingOne New Member

    Joined:
    Mar 16, 2007
    318
    3
    0
    Location:
    -118.15476, 34.112134
    Vehicle:
    2008 Prius
    Could you post the actual file ? It's easier to debug real code :rolleyes:
     
  7. boulder_bum

    boulder_bum Senior Member

    Joined:
    Mar 11, 2007
    1,371
    38
    0
    Location:
    Castle Rock, CO
    Vehicle:
    2007 Prius
    This is really a UI issue more than a data access issue. I personally wouldn't look to a solution inside of a SQL statement, though I'd also use SQL 2005 Express instead of Access for something like this where the UI has grown outside of the "hello world" app that Access is built for.

    A quick look at Access 2007 reveals a "Default Value" property on text boxes in Access. How opposed are you to just set that to 0 and make all of the text boxes required fields.

    Otherwise, you might be able to make a pretty simple VBA script that assigns handlers and listens for change events.
     
  8. eagle33199

    eagle33199 Platinum Member

    Joined:
    Mar 2, 2006
    5,122
    268
    0
    Location:
    Minnesota
    Vehicle:
    2015 Prius v wagon
    Model:
    Two
    I guess that depends on how your implementation goes... If the DB table(s) backing that form was something along the lines of two columns, a date and a value (which is probably how i'd do it on first glance, but other requirements might change that), then you wouldn't have to do it for all 24 fields, just the totals column (so 4 times):

    SELECT sum(iif(isnull(value), 0, value)) FROM table1 WHERE date < 9/30/09 and date > 10/1/07

    The idea isn't to suppress the 0 in each individual field, it's to account for a possible null value in those rows of the database. The SQL query lets you tackle the entire total list in one go, without having to worry about listing out each field. I do not know, maybe i'm missing something in your implementation...

    As someone else said, if you can post the associated file(s) as an example, it would be much easier to debug... if you don't want to do it publicly, feel free to send it to my hotmail account.
     
  9. n8kwx

    n8kwx Member

    Joined:
    Feb 10, 2004
    236
    1
    0
    Location:
    Arlington Heights, IL - NW Chicago Suburb
    Vehicle:
    Other Hybrid
    There is an option in Excel to hide cells with zeros. Might be simpler.
     
  10. TonyPSchaefer

    TonyPSchaefer Your Friendly Moderator
    Staff Member

    Joined:
    May 11, 2004
    14,816
    2,498
    66
    Location:
    Far-North Chicagoland
    Vehicle:
    2017 Prius Prime
    Model:
    Prime Advanced
    Yeah. The reason I started with Excel is that it's easier to set up these types of straight-forward linear records. Problems arose, however, when I needed to add records and generate reports. The records are not always at the bottom of the list and the "reports" coming from Excel are pretty much just printouts from Excel. Without massive amounts of cosmetic trickery, it's difficult to slice and dice the Excel spreadsheet to provide different output options.
     
  11. MegansPrius

    MegansPrius GoogleMeister, AKA bongokitty

    Joined:
    Nov 19, 2006
    2,437
    27
    0
    Location:
    Chicago, IL
    Vehicle:
    2007 Prius
    Model:
    II
    Tony,

    I'm a few years away from when I did a lot of Access work, but you might consider this solely a display problem.

    For example, as previously mentioned, you could set your default field values to 0 to avoid the math problems.

    Then, for your online data entry form or printed report, you could write a simple Macro that performs a set value function (perhaps turning the 0 font color to white or the field background to color to match that of the form) that runs "on load" for the form and "after update" for the field.

    The workability of this sort of depends on whether you're displaying more than one field record in the form and the general design of your data (i.e., is it nearly Excel with one table or is it a buch of cross-linked tables) and whether this is a small or huge database.

    The version of Access you're trying to do this in would also be good to post.