Would help if you posted an error message screenshot, and even a link to an access db file with the table(no data or sample data) and query in question for others to assist in troubleshooting.
I have commented out most of the statements in the startup procedure, the only thing it will do automatically is load the canned reports form, just exit it.
https://drive.google.com/file/d/0B7T2xcfjh34kbk5qa0RIM2RDYUE/view?usp=sharing
Caveat 1 - I am not a database engineer perse, just someone who has learned how to use it, queries reports etc, between classes and practical need, but I am willing to learn of course.
Caveat 2 - I have been trying to avoid VBA, in part due to the fact that its been like 9 years since I did anything with it at all and in part because, if they approve my capital plan, I will get an addon on product wherein the EMR that this data comes from will be autoexported into a full SQL database (meaning every query I try to build in this thing, I try to make full possible in SQL so I can adapt it as I learn more (I can do basic stuff in SQL, at this point).
So with that in mind.
If you open that database and look for the report titled
"Stat - Csection by Provider by Month minus Exclusion
That is derived from a working and more simple report
"Stat - Csection by Provider by Month".
Those exclusions represent maternal deliveries which have complications that mean we can exclude them from reporting in various stats. For example, if a mother has placenta previa, she has to have a csection, etc.
In this report I am trying to create a calculated field in the query for each particular reported stat.
I am working with the most complicated one first, Total Deliveries minus exclusions. What makes it kind of complicated although I am slowly altering the data entry into the EMR itself to solve this, is that these exclusions are documented all over the fucking place and in many case freetexted with several "standard" (meaning shorthand that everyone uses though not necessarily official shorthand) abbreviations. I have begun to make those complications checkboxes instead, so they are more easily searchable.
Anyway, when I first started these queries (this whole statistics gig from this proved by the vendor birthlog was something that sort of fell on me because my bosses found out that I knew my way around access at I guess you would say an intermediate level) I wrote them and would add exclusions in as they came up, and then just manually get lists of patients from several different queries and combine by hand if it was too complex. But I want to simplify that. In part because as my stats job grows, that takes too much time and in part because in the addon product, you can program in the whole thing and automate it.
So, I first came up with a series of iif statements that if an exclusion existed, then it would return 0, if none existed the chain would return 1 and then I would add up the total for that column (and thanks to you Klin, I have been using that way to do this sort of thing since you first mentioned it a year or so ago in a prior question).
I ran into the fact that there is a limit on nested iif statements.
So trying to keep it SQL, and avoid VBA I came up with this (space for clarity)
[FONT="]DelwExcl:[/FONT]
[FONT="]CInt[/FONT]
[FONT="](Switch[/FONT]
[FONT="]((Not IsNull([Infant Delivery Date, Baby B DateTime])),0,[/FONT]
[FONT="][Gestational Age at Deliv Baby A]<37,0,[/FONT]
[FONT="][CSection Incidence]="Repeat",0,[/FONT]
[FONT="][CSection, Primary Indication]="tvrsCmpl",0,[/FONT]
[FONT="][CSection, Primary Indication]="Macro",0,[/FONT]
[FONT="][CSection, Primary Indication]="abrplac",0,[/FONT]
[FONT="][CSection, Primary Ind Other]="*obl*",0,[/FONT]
[FONT="][CSection, Secondary Indication]="abrplac",0,[/FONT]
[FONT="][Matecomp-Placenta Previa]="placprev",0,[/FONT]
[FONT="][Matecomp-Abruptio Placenta]="abr_plac",0,[/FONT]
[FONT="][Matecomp-Preeclampsia]="Preecl",0,[/FONT]
[FONT="][Intrapartum Maternal Complicatio]="placprev",0,[/FONT]
[FONT="][intrapartum maternal complicatio]="abr_plac",0,[/FONT]
[FONT="](Not IsNull([Method of Delivery Baby A])),1))[/FONT]
I have several more exclusions to add. I want to get to this (There are potentially more exclusions in more places to add to this, some are really rare and the PI person just mentions them to me when they come up. She used to do this whole process by hand, going through every chart).
[FONT="]DelwExcl: [/FONT]
[FONT="]CInt[/FONT]
[FONT="](Switch[/FONT]
[FONT="]((Not IsNull([Infant Delivery Date, Baby B DateTime])),0,[/FONT]
[FONT="][Gestational Age at Deliv Baby A]<37,0,[/FONT]
[FONT="][CSection Incidence]="Repeat",0,[/FONT]
[FONT="][CSection, Primary Indication]="tvrsCmpl",0,[/FONT]
[FONT="][CSection, Primary Indication]="Macro",0,[/FONT]
[FONT="][CSection, Primary Indication]="abrplac",0,[/FONT]
[FONT="][CSection, Primary Ind Other]="*obl*",0,[/FONT]
[FONT="][CSection, Secondary Indication]="abrplac",0,[/FONT]
[FONT="][Matecomp-Placenta Previa]="placprev",0,[/FONT]
[FONT="][Matecomp-Abruptio Placenta]="abr_plac",0,[/FONT]
[FONT="][Matecomp-Preeclampsia]="Preecl",0,[/FONT]
[FONT="][Intrapartum Maternal Complicatio]="placprev",0,[/FONT]
[FONT="][intrapartum maternal complicatio]="abr_plac",0,[/FONT]
[FONT="][VBAC Baby A]=Success,0,[/FONT]
[FONT="][Fetal Presentation Baby A] = Compound,0,[/FONT]
[FONT="][Fetal Presentation Baby A] = Breech,0,[/FONT]
[FONT="](Not IsNull([Method of Delivery Baby A])),1))[/FONT]
[FONT="][/FONT]
[FONT="]I am fairly certain that I am not missing a comma anywhere.[/FONT]
[FONT="][/FONT]
[FONT="]The message that I get is usually[/FONT]
[FONT="][/FONT]
[FONT="]"Expression to complex to evaluate" or something similar.[/FONT]
[FONT="][/FONT]
[FONT="]My research today tells me that either I have hit the maximum about of things you can put into a switch statement, or I am running into the maximum character limit on Access SQL statements, which is something like 1024 characters in Access 2007 (which is the version that I have).[/FONT]
[FONT="][/FONT]
[FONT="]I thought at first that I was running into an access 2007 bug that it has to saving things inside the query inside reports.[/FONT]
[FONT="][/FONT]
[FONT="]So, if I what I found is true, is my only option to write VBA code.
[/FONT]
[FONT="][/FONT]
[FONT="]At that point, if so, I would basically have the VBA code evaluate a series if If/then/else statements, stopping when it found an exclusion. I don't think that I can use a Select Case because there are multiple fields that I have to look into, some of which contain different data types.[/FONT]
[FONT="][/FONT]
[FONT="]Any help is appreciated. I am always willing to learn
[/FONT]