Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    GCLIFTON is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    84

    iF THEN VBA STATMENT

    Need help with vba/sql if then statment

    See the below. In the Tracker. Table. which is populated by a form having check boxes. I would like in query how to write the statement If Columns by unit, starting with [1 Demo], has a -1 then give me whats in [Tracker_Budget_Upload_. [1 Demo] that corresponds with that unit



    Tracker
    Click image for larger version. 

Name:	Tracker.jpg 
Views:	19 
Size:	158.2 KB 
ID:	25151

    Tracker_Budget_upload_
    Click image for larger version. 

Name:	Tracker 2.GIF 
Views:	19 
Size:	253.1 KB 
ID:	25152

    This is what i attempted- Demo: IIF(Tracker.[1 Demo]="-1",Tracker_Budget_Upload_.[1 Demo]

  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,652
    That's incomplete, and if it's a Yes/No field you wouldn't want the quotes. Try

    Demo: IIF(Tracker.[1 Demo]=-1,Tracker_Budget_Upload_.[1 Demo]. 0)

    Or whatever you want for the False argument.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You can do this with a query, no vba.
    select table.tracker from table where table2.[1 demo]

  4. #4
    GCLIFTON is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    84
    OK I Recieiving the false statement when i changed it to "" but i am not receive any value of 100 for 1932-3

  5. #5
    GCLIFTON is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    84
    That is how i am doing this. In Design view in The Field column. Are you stating something different that i should do

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Perhaps it isn't a Yes/No field. Try with the quotes:

    Demo: IIF(Tracker.[1 Demo]="-1",Tracker_Budget_Upload_.[1 Demo]. "")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Just to verify - you do have a query with both tables in it, joined on the "combine" field?

    You could try using a True/False comparison, since that is what checkboxes give you:

    Demo: IIF(Tracker.[1 Demo]=True,Tracker_Budget_Upload_.[1 Demo], "")

  8. #8
    GCLIFTON is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    84
    John that was it. I totally forgot to join the tables duh lol. And quick questions for any one to answer, why does this sql doesn't work. and what should it be. Total:Sum([window]+[Demo]+[MEP Rough]+[Bathtub]) I have tried with a , and + . With the + i get the numbers joined together. For instance 49.7657+100.00 will equal 49.7657100. Not 149.555. And then when i use , i get an error stating i cant not sum fields with "*"

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I can tell from the way they left-align that your fields are text. That will cause them to concatenate rather than add. If they are supposed to hold numeric values, they should have a numeric data type. A kludge workaround would be using the appropriate conversion function around each (CCur(), CDbl(), etc).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    GCLIFTON is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    84
    Ok maybe i am missing something, This is what i tried. Well first i went back to the table and made the data currency. Then i tried the following and the results

    Total: (CDbl([Demo]+[Window]+[MEP Rough]))
    Click image for larger version. 

Name:	table 1.GIF 
Views:	10 
Size:	157.5 KB 
ID:	25178

    Total: ([Demo]+[Window]+[MEP Rough])
    Click image for larger version. 

Name:	table2.GIF 
Views:	10 
Size:	162.5 KB 
ID:	25179

    Total: (CCur([Demo]+[Window]+[MEP Rough]))
    Click image for larger version. 

Name:	Table3.GIF 
Views:	9 
Size:	112.9 KB 
ID:	25180

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I mentioned around each, so more like:

    Total: CDbl([Demo])+CDbl([Window])+CDbl([MEP Rough])

    given your de-normalized design with what must be Nulls:

    Total: CDbl(Nz([Demo],0))+CDbl(Nz([Window],0))+CDbl(Nz([MEP Rough],0))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    GCLIFTON is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    84
    That worked 2 question left

    1. Why are there #Error signs. I have been trying to figure out why and get rid of them
    Click image for larger version. 

Name:	table4.GIF 
Views:	8 
Size:	90.0 KB 
ID:	25184

    And how can i get rid of all of the columns to the right of Total1. Like 1demo, and 3 Windows. I dont even have them in my design view Fields

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    What's the SQL? You may have a "*" in there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    GCLIFTON is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    84
    Just figured out the error problem. So is there a way to romove the columns that i ddin't select

  15. #15
    GCLIFTON is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    84
    This one

    SELECT Tracker.Combine, Tracker.[Floor Plan], Tracker.Type, Tracker.Scope, IIf([Tracker].[3 Windows]="-1",[Tracker_Budget_Upload_].[3# Windows],0) AS Window, IIf([Tracker].[1 Demo]="-1",[Tracker_Budget_Upload_].[1# Demo],0) AS Demo, IIf([Tracker].[4 Mep Rough]="-1",[Tracker_Budget_Upload_].[4# Mep Rough],0) AS [MEP Rough], IIf([Tracker].[6 Bathtub]="-1",[Tracker_Budget_Upload_].[6# Bathtub],0) AS Bathtub, CDbl(Nz([Demo],0))+CDbl(Nz([Window],0))+CDbl(Nz([MEP Rough],0)) AS Total1, *
    FROM Tracker INNER JOIN Tracker_Budget_Upload_ ON Tracker.Combine = Tracker_Budget_Upload_.Combine;

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. If Statment Issues
    By Wasp1 in forum Modules
    Replies: 3
    Last Post: 04-30-2014, 11:43 AM
  2. if statment
    By ismailkhannasar in forum Access
    Replies: 3
    Last Post: 01-31-2013, 06:48 AM
  3. if statment or case statment?
    By whojstall11 in forum Forms
    Replies: 4
    Last Post: 07-09-2012, 01:44 PM
  4. is this a valid statment
    By akrylik in forum Access
    Replies: 12
    Last Post: 05-08-2012, 08:47 PM
  5. Like statment
    By brew in forum Programming
    Replies: 2
    Last Post: 12-01-2011, 03:23 AM

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