Results 1 to 14 of 14
  1. #1
    GetRektByNoob is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    22

    Exclamation If statement in query

    hello guys.


    im trying you use the if statement to show a row of kind if an another row is euqal to something. in c# to make it more clear
    Code:
    if(PhoneType.euqal("32GB"))
    {
    //Show phone 32GB price by phone id
    } else {
    //Show phone 64GB price by phone id
    }
    the sales query https://imgur.com/a/gl9qMwH (the prices here only show the 32GB so if the phone is 64GB its going to show the 32GB version of the phone)
    64GB phones http://prntscr.com/nwj9dd
    32GB phones http://prntscr.com/nwj9j3

    thanks for the help. (im not good in accsess to please keep it simple )

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Not much to go on here; pictures of query results don't help at all (at least not me).
    I think what you need is an expression in a query field that uses IIF function.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If you have two tables for PhoneTypes, should be 1.

    Quite possibly in IIf() expression will serve.
    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.

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    In the 3rd photo it appears you have tables - Phone Types- 64GB and Phone Types- 32GB.
    Are you storing data AS tables? Are these tables the same except for 64 and 32?

  5. #5
    GetRektByNoob is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    22
    @Micron I know, this is what I'm trying to do... but it's not working for me because I'm not good with access.

    @June7 its not 1 table because the 32 and 64 doesn't have the same stats each phone has a different stats. ()

    @moke123 the only thing that is similar is the ID and the name apart from that everything should be different.
    Last edited by GetRektByNoob; 06-02-2019 at 10:35 PM. Reason: to be more clear

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Both tables have the same PhoneID. Build a query that joins those to the sales data and use an IIf() expression to pick the appropriate price.

    What fields are different?

    If you want to provide db for analysis, follow instructions at bottom of my 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.

  7. #7
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    I am not good at VBA but isn't "equal" spelled wrong in the If statement? if(PhoneType.euqal("32GB"))

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Doesn't matter since it was a C# example not VBA.

    In query, probably want something like:

    IIf(PhoneType = "32GB", this field name, other field name)

    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.

  9. #9
    GetRektByNoob is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    22
    Quote Originally Posted by June7 View Post
    Doesn't matter since it was a C# example not VBA.

    In query, probably want something like:

    IIf(PhoneType = "32GB", this field name, other field name)

    yes, this i what is need
    i did
    Code:
    Price: IIf([Sales]![Phone Type]="32GB",[Phone Types 32GB]![Price],[Phone Types 64GB]![Price])
    in the Field row but its not working and its asking for params when activating the query.

  10. #10
    GetRektByNoob is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    22

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Query does not include the 64GB table.

    The two phone tables have the same fields.

    Many will not download file from other sites. Best to attach Zip file to 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.

  12. #12
    GetRektByNoob is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    22
    Quote Originally Posted by June7 View Post
    Query does not include the 64GB table.

    The two phone tables have the same fields.

    Many will not download file from other sites. Best to attach Zip file to post.
    they have the same fields but but same not same values.

    ok.

    how do i make it so?

  13. #13
    GetRektByNoob is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    22
    oh just had to include the 64 table xD tnx for the help!

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Of course they have different data. But since fields are the same, this can be 1 table. Options:

    1. Two price columns and use the IIf() to pull correct one.

    2. Each phone/price pair is a separate record. Have a column to identify as 32GB or 64GB. Will have to change PhoneID keys in Sales and Company Phone. No need for PhoneType field in Sales.
    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. Replies: 8
    Last Post: 05-08-2018, 07:27 AM
  2. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  3. Replies: 3
    Last Post: 07-10-2012, 05:23 AM
  4. query iif statement help
    By swat in forum Queries
    Replies: 4
    Last Post: 09-30-2011, 11:48 AM
  5. If then statement in query
    By ronnie4 in forum Queries
    Replies: 1
    Last Post: 01-20-2009, 10:49 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