Results 1 to 9 of 9
  1. #1
    melvinhagar is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    23

    How to create a field in a query

    I want to create a new field ONLY within a query. I don't wish to create a new field at the table level. I see that I can create a "calc" field within a query, but that involves mathmatical expression and numbers. I want to create a new field and populate its' value based on values in another existing field. Ex. If Table Field 1 contains the value "A", I want my query-only field to return value of "Apple". If Table Field 1 contains the value "O", I want my query-only field to return a valule of "Orange". Can this be done? I can find no helps on this. Everything I find talks about calc fields, or adding fields at the table level.

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Use the same method as a calculated field: Field name: value

    e.g. TestField1: "A"
    or TestField2:IIf(ThisTable.Field1="A","Apple",IIf(Th isTable.Field1="O","Orange"),etc)

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    What Aytee111 said. The key is the colon, left of it will be the name of column in the query. You can use this also to change the name of a column so say in table the field is called ProdNbr, in query you could change it to Product Number: [ProdNbr] so when you run the query it displays correctly.

  4. #4
    melvinhagar is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    23
    Nah. Can't get it to work. Can't get around syntax errors/issues and it offers no help with that. Tried format as given above by aytee111: TestField2:IIf(ThisTable.Field1="A","Apple",IIf(Th isTable.Field1="O","Orange") Format not acceptable.

  5. #5
    melvinhagar is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    23
    I guess I need to know in the calc field, what goes in the "Field" cell, the "Table" cell, and the "Criteria". I'm assuming the logic of the calc field goes in the criteria cell.

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In your first answer above there is a missing right parenthesis. Each IIf has an opening as well as a closing bracket.

    This will go in the Field line. The table line will usually be empty (Access will decide that). The criteria field will be filled in with your criteria if you want any, such as ="Apple" or "Orange".

  7. #7
    melvinhagar is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    23
    I tried this in the Field line: EVP Group:IIf(EVP Level="EVP","EVP 0-3"),IIf(EVP Level="EVP-1","EVP 0-3"),IIf(EVP Level="EVP-4","EVP 4-99") .... got syntax errors. Attached are the details of what I'm trying to accomplish:
    Attached Thumbnails Attached Thumbnails Capture.JPG  

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    you have to nest the if statement if you're going to have multiple categories but you really only have two"

    iif([evp level] = "EVP" or [evp level] = "EVP-1" or [evp level] = "EVP-2" or [evp level] = "EVP-3", "EVP 0-3", "EVP 4 - 99")

    p.s. stay away from spaces or special characters in your field names it makes them harder to deal with you'd be better off with a field named evp_level

  9. #9
    melvinhagar is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    23
    WORKED!!!! Thanks much rpeare.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-21-2015, 11:26 AM
  2. Replies: 5
    Last Post: 04-04-2014, 03:33 PM
  3. How do i create a new field in a query
    By jayjayuk in forum Access
    Replies: 3
    Last Post: 10-12-2010, 09:06 AM
  4. How do i create a new field in a query
    By jayjayuk in forum Access
    Replies: 1
    Last Post: 10-12-2010, 07:25 AM
  5. Replies: 3
    Last Post: 04-26-2010, 11:38 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