Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28

    field statement with if then else

    I try this but how to do it correct



    I try to make a field statement but need some help to use if then else
    Test:

    If (([tblStamData]![Stilling] = test

    then

    ([tblBonus]![OverTid50]*[tblBonus]![Overtid50Antal])

    else

    ([tblBonus]![OverTid100]*[tblBonus]![Overtid100Antal])

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    You want to do this in query to construct a field?

    Test: IIf([Stilling] = "some value here", [OverTid50] * [Overtid50Antal], [OverTid100] * [Overtid100Antal])

    tblStamData and tblBonus tables must both be in the query design.
    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.

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Are you doing this in a Query or VBA?

    If in a Query, you would use an IIF statement (see: http://www.techonthenet.com/access/f...vanced/iif.php).

    So it would look like:
    Code:
    Iif([tblStamData]![Stilling] = test,[tblBonus]![OverTid50]*[tblBonus]![Overtid50Antal],[tblBonus]![OverTid100]*[tblBonus]![Overtid100Antal])
    Note that if you are looking for the literal string test, you will need to include it in quotes, i.e.
    ="test"
    Otherwise, it is looking for a field or variable named test.

  4. #4
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28
    Thanks but what about the else statement ?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    It's built into the IIf() function. Review the link referenced by JoeM.


    Ooops, Joe I get a 'page not found' on that link.

    Search Access Help or the web.
    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.

  6. #6
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28
    What about the else statement

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Did you see my previous post?
    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.

  8. #8
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28
    yes thanks I will try

  9. #9
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28
    I get error in my test of the code, I get the message

    "The input expression contains an invalid syntax"

    can anybody see what is wrong here ?

    Test:
    Iif([tblStamData]![Stilling] = "Testing",
    ([tblStamData]![Løn]*[tblBonus]![Overtid50Antal]),
    ([tblStamData]![Løn]*[tblBonus]![Overtid100Antal]))
    Last edited by darwin; 05-12-2015 at 01:44 AM. Reason: optimizing question

  10. #10
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Where exactly are you putting this formula?
    In a query or somewhere else?
    If in a query, are tblStamData and tblBonus in your query?

  11. #11
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28
    it is not a formula, it is in a Query.

    yes tblStamData and tblBonus is in the Query

    In the Query I make a fictive field Test.

  12. #12
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    What version of Office are you using?
    If it an US version or a European version?
    Some European versions use semi-colons instead of commas as argument separators (in which case you would need to replace the commas with semi-colons).

  13. #13
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28
    Danish-European access 2013

  14. #14
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    So, if you replace your commas with semi-colons, does it work?

    Test: Iif([tblStamData]![Stilling] = "Testing";
    ([tblStamData]![Løn]*[tblBonus]![Overtid50Antal]);
    ([tblStamData]![Løn]*[tblBonus]![Overtid100Antal]))

  15. #15
    darwin is offline Novice
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    28
    welll no error

    but after I run the Query a message box pop up with the message enter the parameter value
    for the tblStamdata!Stilling

    here is the screendump
    Click image for larger version. 

Name:	popup.png 
Views:	9 
Size:	13.6 KB 
ID:	20652
    Last edited by darwin; 05-12-2015 at 08:42 AM. Reason: pictures

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

Similar Threads

  1. Replies: 8
    Last Post: 06-09-2014, 01:14 PM
  2. If then statement on calculated field
    By blakej in forum Access
    Replies: 9
    Last Post: 03-17-2014, 01:12 PM
  3. Replies: 3
    Last Post: 05-06-2013, 03:03 PM
  4. If statement in form field
    By Gabriel2012 in forum Forms
    Replies: 1
    Last Post: 01-29-2013, 05:03 PM
  5. IIF statement to populate field
    By GriffyNJ in forum Queries
    Replies: 0
    Last Post: 10-13-2009, 10:07 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