Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    techexpressinc's Avatar
    techexpressinc is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2008
    Location
    Indiana, USA
    Posts
    151

    if or syntax help needed

    I have to flip values for a field.



    if the field Q12 has a 1 - I need to change it to a 5.
    if the field Q12 has a 2 - I need to change it to a 4.
    etc.

    I have tried this without success.
    Q12A: IIf([Q12]=1,5),Iff([Q12]=2,4)

    Can someone point me to the right syntax?

    Thanks
    Russ

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    And if it is neither value?

  3. #3
    techexpressinc's Avatar
    techexpressinc is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2008
    Location
    Indiana, USA
    Posts
    151

    I need to switch values on a field.values 0 thru 5

    I need to switch values on a field; values 0 thru 5.
    0 stays 0
    1 goes to 5
    2 goes to 4
    3 stays 3
    4 goes to 2
    5 goes to 5

    I have coded this for a started for the concept but syntaxly failing.
    Q12A: IIf([Q12]=1,5),Iff([Q12]=2,4)


    Thx
    Russ

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Create a Public Function in a Standard Module that uses a Select Case structure. It will be easier to understand and maintain. A nested IIF is hard to read. Do you know how to do that? Post back if you need further assistance.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is the field numeric (Integer, Long, Single, Double) or a string?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Here's what it would look like if the field is an Integer:
    Code:
    Public Function MySwitch(InValue As Integer) As Integer
        Select Case InValue
            Case 1
                MySwitch = 5
            Case 2
                MySwitch = 4
            Case 3
                MySwitch = 3
            Case 4
                MySwitch = 2
            Case 5
                MySwitch = 1
            Case Else
                MySwitch = InValue
        End Select
            
    End Function

  7. #7
    techexpressinc's Avatar
    techexpressinc is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2008
    Location
    Indiana, USA
    Posts
    151
    Number Integer is the field.

  8. #8
    techexpressinc's Avatar
    techexpressinc is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2008
    Location
    Indiana, USA
    Posts
    151
    Rural Guy - thanks for the code and idea I will attempt to implement it today and let you know how it goes.
    Rus

  9. #9
    techexpressinc's Avatar
    techexpressinc is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2008
    Location
    Indiana, USA
    Posts
    151
    i could not figure out how to install the function so i coded it like this
    Q12A: IIf(([Q12]=1),5,IIf(([Q12]=2),4)) .... etc

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You would have put the function I supplied in a standard module, not a form. Then in the query you simply put:
    Q12A:=MySwitch([Q12])

  11. #11
    techexpressinc's Avatar
    techexpressinc is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2008
    Location
    Indiana, USA
    Posts
    151

    how do you add a standard module - MSAccess2007

    Do I click Database Tools - Visual Basic - insert module and paste it there?

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    On the right side of the Create Ribbon is Module. Press it.

  13. #13
    techexpressinc's Avatar
    techexpressinc is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2008
    Location
    Indiana, USA
    Posts
    151
    Rural Guy - Good Job! - You came through again. Your module is installed and working. My code is this for the 6 values needing the flip.
    " Q12AA: MySwitch([Q12]) "
    Thx
    Keep up the good work you are going down in Cyber History.
    Russ

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    And you are wiser today than yesterday. Aren't you glad you kept going? You have unleashed the power of code and modules.

  15. #15
    techexpressinc's Avatar
    techexpressinc is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Dec 2008
    Location
    Indiana, USA
    Posts
    151
    Yes. Glad I kept at it. The module creation process - i have tried and failed a half dozen times in the past with.
    Russ

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

Similar Threads

  1. Sql Syntax Query
    By Matthieu in forum Queries
    Replies: 4
    Last Post: 12-30-2009, 09:41 AM
  2. Looping syntax
    By fadiaccess in forum Access
    Replies: 1
    Last Post: 10-23-2009, 02:57 AM
  3. Syntax-reference to pages
    By AmyHill in forum Access
    Replies: 5
    Last Post: 08-27-2009, 10:04 AM
  4. sql syntax error
    By SMAlvarez in forum Access
    Replies: 1
    Last Post: 03-12-2009, 09:43 PM
  5. Syntax Error In Insert Into Statement
    By frankvfox in forum Queries
    Replies: 1
    Last Post: 09-09-2008, 12:35 PM

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