Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125

    Report Control Source Manipulation

    I am searching for the proper (if possible) control source code to (1) print "Yes" when the table field is "True" and use case values 1 to 5 to insert a different phrase for each number. I gather that "If Then logic" isn't used in "Expression Builder"! Also is there a similar technique for Queries? TIA Phil

  2. #2
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    print "Yes" when the table field is "True"
    If this is a boolean (Yes/No) field in your table then a simple IIf statement should suffice;

    IIf([YourField]=0, "False, "True")

    values 1 to 5 to insert a different phrase for each number.
    You could use a nested IIf statement here;

    IIf([YourField]=1, "Text 1", IIf([YourField] = 2, "Text 2", IIf([YourField]=3, "Text 3"....and so on

    However, nested IIf statements can become a bit cumbersome and difficult to read when you have several conditions. A couple of other options;

    The Choose function, which simply chooses the value based on it's position in the list as compared to the index value (which in this case would be the value 1 - 5 in your field).

    Choose([YourField],"Text 1","Text 2","Text 3","Text 4","Text 5")

    Or, the Switch function, similar to the Choose function but it takes pairs of arguments;

    Switch([YourField]=1,"Text 1",[YourField]=2,"Text 2",[YourField]=3,"Text 3",[YourField]=4,"Text 4",[YourField]=5,"Text 5")

  3. #3
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    Thanks for your response. I managed to code the Iff function with no problem. however when I attempted to use Choose or Switch functions I get a string error or syntax "comma" error here is my code
    =Switch([PoliticalPreference]=1,"Democrat",[PoliticalPreference]=2,"Independent",[PoliticalPreference]=3,“NonVoter",[PoliticalPreference]=4,"Tea Party",[PoliticalPreference]=5,"Republican")

    =Choose([PoliticalPreference],"Democrat","Independent","[NonVote]","[Tea Party]","Republican”) . The Table has values 1 for Democrat, 2 for Independent, etc. I placed spaces after comma with no change. To my untrained eye, my code appears correct. Where am I errors? TIA Phil

  4. #4
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    I’ve tried the examples shown below and I always get syntax errors or a window asking for choice number. Please what am I doing wrong?
    =Choose([PoliticalPreference],"Democrat","Independent","Non Voter","Tea Party","Republican”)
    =Choose([PoliticalPreference],"Democrat","Independent","[Non Voter]","[Tea Party]","Republican”)
    =Choose([PoliticalPreference],"Democrat” 1,"Independent” 2,"Non Voter” 3,"Tea Party” 4,"Republican” 5)
    =Choose([PoliticalPreference],"Democrat 1”,"Independent 2”,"Non Voter 3”,"Tea Party 4”,"Republican 5”)
    TIA Phil

  5. #5
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    You may want to try the Case Select.

    Code:
    Select Case Combo0
        Case 1
             something
         Case 2
            something different
    End Select
    Dale

  6. #6
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    Thanks for the idea, but it resulted in a message box requesting a parameter value. I placed this code in the report field Control Source:
    =[Select Case Combo() Case 1 "Democrat" Case 2 "Independent" Case 3 "Non Voter" Case 4 "Tea Party" Case 5 "Republican" End Select ]
    Any suggestions? TIA Phil

  7. #7
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Sorry Philip.

    This code should be in an event.
    Combo0 should be replaced with your combo box or whatever you are using to select your data.

    I would make a combo box to hold your selections and put this code on the After UpDate event.

    Let us know if your are still having problems.

    Maybe upload your database would help.

    Dale

  8. #8
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    Thanks for the response! This field is in a report. Can a report field access an event procedure? I tried {=[Select Case PoliticalPreference() Case 1 "Democrat" Case 2 "Independent" Case 3 "Non Voter" Case 4 "Tea Party" Case 5 "Republican"]} in the field control source and on the attempted execution of the report I get the usual message window asking to "Enter Parameter Value." I really don't want to place the text in another table route, that logic I have used successfully before; I'm trying to learn new techniques and broaden my understanding, like with Iffs, Choose and Switch. Always a syntax error with these functions. Phil

  9. #9
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Philip,
    How are you opening this report?

    Dale

  10. #10
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    After making a corrective change to the Control Source code, I press enter to go to the next property entry (If Access allows me to do this, the code is saved in the control Source changes are saved. I then click on the Print Preview tab. No report preview has every occurred with selective code in the property control source. Phil

  11. #11
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    After making a corrective change to the Control Source code, I press enter to go to the next property entry (If Access allows me to do this, the code is saved in the control Source changes are saved. I then click on the Print Preview tab. No report preview has every occurred with selective code in the property control source.
    Philip, I have no idea what you are talking about.


    Dale

  12. #12
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    If the code has a syntax error, Access will not save it and allow you to open the report (switch Views). Since the report is in development stage, I switch between Design and Execute window through the View Tab. Phil

  13. #13
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Philip,
    How are you opening this report?

    Dale
    FROM where are you trying to open this report?
    A form? What?
    You have lost me completely.

    Dale

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In post #3, there is an incorrect character.The double quote in front of Nonvoter shouold be replaced (in red):
    Code:
    =Switch([PoliticalPreference]=1,"Democrat",[PoliticalPreference]=2,"Independent",[PoliticalPreference]=3,NonVoter",[PoliticalPreference]=4,"Tea  Party",[PoliticalPreference]=5,"Republican")
    It should be:
    Code:
    =Switch([PoliticalPreference]=1,"Democrat",[PoliticalPreference]=2,"Independent",[PoliticalPreference]=3,"NonVoter",[PoliticalPreference]=4,"Tea  Party",[PoliticalPreference]=5,"Republican")

  15. #15
    justphilip2003 is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ohio
    Posts
    125
    Than you so very much! I could not see the forest for all of the trees! LOL Small print is hard for me to see. Phil

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

Similar Threads

  1. Two passes through report's control source?
    By GraeagleBill in forum Reports
    Replies: 2
    Last Post: 09-03-2012, 05:50 PM
  2. Replies: 5
    Last Post: 10-13-2011, 03:36 PM
  3. Replies: 2
    Last Post: 08-18-2011, 11:40 AM
  4. control source
    By nashr1928 in forum Forms
    Replies: 5
    Last Post: 03-12-2011, 09:31 PM
  5. Control Source
    By sarah54 in forum Access
    Replies: 1
    Last Post: 03-07-2011, 09:00 PM

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