Solved

Switch

Posted on 2013-06-10
9
330 Views
Last Modified: 2013-06-10
Experts,

I get an error of Wrong Number of Arguments.  Do you see where the error is?  
The below use to be an IIF (that worked fine) but I switched it to a "SWITCH" because I needed to add another condition.  I imagine it is a syntax somewhere.  thank you.

MyGroup: Switch(([tblStatus.Status] Like "*Awarded*" Or [tblStatus.Status] Like "Won*" Or IsNull([ContractAward])=False,"Awarded - within last 60 days", [ATTApprvDate] Is Not Null and [ContractAward] is Null, "Went to ATT but not Awarded", GetGroup([Projects.BidCloseDate],[Projects.ATTApprvDate],[Projects.ATCApprvDate],[Projects.ATSApprvDate],[Projects.ContractAward],[Projects.CorpATTDate],[Projects.ExpectedContractAward])))
0
Comment
Question by:pdvsa
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39234597
If GetGroup returns a True/False response then you're missing the argument after it if the response is True.  If GetGroup returns a response other than True/False, this needs to be dealt with first.
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 39234614
Wait a minute, did you want to return the result of GetGroup if neither of the first 2 criteria wetter met?  If so, then add "TRUE," (without the quotes) right before GetGroup.
0
 

Author Comment

by:pdvsa
ID: 39234685
I added the TRUE and I dont have any errors.  BUT it doesnt want to save it?  


I Have it as follows: (only difference from initial post is the "True" (in bold) and when I tab out it doesnt give any errors and I close and save but when I open again it reverts back to the original.
Strange. Any idea why it it wont save as below?

MyGroup: Switch(([tblStatus.Status] Like "*Awarded*" Or [tblStatus.Status] Like "Won*" Or IsNull([ContractAward])=False,"Awarded - within last 60 days", [ATTApprvDate] Is Not Null and [ContractAward] is Null, "Went to ATT but not Awarded","True", GetGroup([Projects.BidCloseDate],[Projects.ATTApprvDate],[Projects.ATCApprvDate],[Projects.ATSApprvDate],[Projects.ContractAward],[Projects.CorpATTDate],[Projects.ExpectedContractAward])))
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39234693
1. Too many parenthesis.

2.  When wrapping [table.field] in brackets, each should have its own opening and closing brackets [table].[field]

3.  As IrogSinta indicates, you must have an even number of parameters.  Your call to GetGroup must either return a True/False value or be evaluated against some other value to get a True/False.  Then you need to return a return value for the Switch statement for that element.

4.  I always (while debugging a Switch statement) include a final pair of parameters  (True, "No Match") in my Switch statements so that I can identify records that don't meet any of the parameters provided.  

Switch([tblStatus.Status] Like "*Awarded*" Or [tblStatus.Status] Like "Won*" Or IsNull([ContractAward])=False,"Awarded - within last 60 days",
[ATTApprvDate] Is Not Null and [ContractAward] is Null, "Went to ATT but not Awarded", GetGroup([Projects].[BidCloseDate],[Projects].[ATTApprvDate],[Projects].[ATCApprvDate],[Projects].[ATSApprvDate],[Projects].[ContractAward],[Projects.CorpATTDate],[Projects.ExpectedContractAward]), "Get Group", True, "No Match")
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 500 total points
ID: 39234700
As I mentioned, don't include the quotes. It's just True,
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 39234703
If you need a refresher on how to use the Switch function, please have a look at my article here.

I think Ron has nailed the reason you are getting that error: You have an odd number of arguments in your Switch expression, which is a no-no.  If your intent is, "if all else fails, then return the value from the GetGroup() expression", then Ron is correct that you need to preface that with an expression that is always true:

MyGroup: Switch([tblStatus.Status] Like "*Awarded*" Or [tblStatus.Status] Like "Won*" Or [ContractAward] Is Not Null,"Awarded - within last 60 days", [ATTApprvDate] Is Not Null And [ContractAward] is Null, "Went to ATT but not Awarded", True, GetGroup([Projects.BidCloseDate],[Projects.ATTApprvDate],[Projects.ATCApprvDate],[Projects.ATSApprvDate],[Projects.ContractAward],[Projects.CorpATTDate],[Projects.ExpectedContractAward]))

Open in new window


Note that while the simple boolean value True is sufficient, you can also do things like 1=1.  I address this "none of the above" option in my article.
0
 

Author Closing Comment

by:pdvsa
ID: 39234752
thank you.  Fyed:  it said I have a criteria mismatch error (or something like that)... OK thanks guys....gotta run...
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39234985
That's a pretty good article, Matthew. Very extensive.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 39235302
Thanks for the compliment, Ron :)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now