473,748 Members | 9,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IIf statement not working, SELECT case instead?

18 New Member
I have a very long IIf statement. I think maybe I've reached the limit of how many choices you can have in the control source "Build" statement of a text box on a form. Really, the IIF statement is very confusing looking at it, so I suppose there is a better way, but I don't know how. When I try to add additional choices, nothing happens, I save, get no errors, but the new choices don't work! I am trying to calculate a due date [DATEREVIEWDUE]text field on a subform based off of the value chosen in another subform on the same main form using a field called [TASKTYPE]. Whatever value is chosen in TASKTYPE (dropdown box) it is compared with the value in the [DATEREVIEWASSIG NED] text box which calculates the DATEREVIEWDUE. It works for many instances, but when I tried to add additional options beyond 14 choices, access doesn't save the changes. It will only allow me to change the existing entries. I've attached the sample code of my current IIf statement that works. Thanks in advance.

** Edit ** Added text and removed attachment (as the attachment requires downloading which makes it a little hard to see normally).

Expand|Select|Wrap|Line Numbers
  1. =IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Alternatives Analysis",[DATEREVIEWASSIGNED]+60,
  2.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Explore",[DATEREVIEWASSIGNED]+7,
  3.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="GP-12",[DATEREVIEWASSIGNED]+30,
  4.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Informal",[DATEREVIEWASSIGNED]+45,
  5.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Major 1",[DATEREVIEWASSIGNED]+60,
  6.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="New 1",[DATEREVIEWASSIGNED]+60,
  7.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Noise Complaint",[DATEREVIEWASSIGNED]+30,
  8.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Other",[DATEREVIEWASSIGNED]+30,
  9.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Renewal",[DATEREVIEWASSIGNED]+60,
  10.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Revision",[DATEREVIEWASSIGNED]+90,
  11.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Special Project",[DATEREVIEWASSIGNED]+60,
  12.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Stream Investigation",[DATEREVIEWASSIGNED]+60,
  13.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Transfer",[DATEREVIEWASSIGNED]+60,
  14.  IIf(Forms![Input Facility Task Reviewer]!Task_Subform.Form!TASKTYPE="Water Loss",[DATEREVIEWASSIGNED]+45))))))))))))))
Oct 29 '09
40 6239
chhines
18 New Member
ADezii. When I try to add the debug line, I get, "compile error: Invalid Outside procedure." I've tried adding it in the "Input Facility Task Reviewer" portion of VB and also in the "Reviewer_F orm" portion, same error. No I didn't forget to set the function as the control source for [DATEREVIEWDUE].

NeoPA, no I didn't try your idea, it wasn't that I didn't want to, just I had gotten pretty close with ADezii's idea. I feel we're right there. A lot of the data in the database is confidential, so I'm not sure that I would want to upload the database.
Nov 2 '09 #11
ADezii
8,834 Recognized Expert Expert
@chhines
To be perfectly honest, I'm pretty much out of options at this point. Unless you can replace the confidential data with Dummy Data (only a couple of Records should do), there isn't much else that I can offer. Another option would be to Upload a simulated Database to me at my Personal E-Mail Address outside of this Forum. Whatever you decide to do, it's your choice.
Nov 2 '09 #12
chhines
18 New Member
ADezii, I'll try breaking it down some tonight and will repost back here something you can work with...Thanks.
Nov 2 '09 #13
chhines
18 New Member
ADezii, I've attached a copy of the database---modified.
I didn't put a lot of data in it, it appears to be still making the same error with what I have in there.
Hopefully you can figure something out from what I have in there.
If you need to, add additional data, or let me know and I'll add more records. Thanks again.
Attached Files
File Type: zip WorkloadAnalysisME.zip (137.8 KB, 80 views)
Nov 2 '09 #14
NeoPa
32,571 Recognized Expert Moderator MVP
If you'd prefer even that be kept private, I'm happy to remove it for you after ADezii has downloaded his copy. Just let me know.
Nov 2 '09 #15
ADezii
8,834 Recognized Expert Expert
@chhines
I've made many changes to your Database, some of which I'll point out here, and I'll also make certain notations. The rest will be up to you. Study the Attachment for details.
  1. CalcDueDate() is now a Public Function in the SendMail Module.
  2. [cboTASKTYPE] is now Bound to [TASKTYPE]
  3. [DATEREVIEWASSIG NED] is now Bound to [DATEREVIEWASSIG NED]. It's Control Source equal to the Function has been removed.
  4. Look at the same code in the AfterUpdate() Event of [cboTASKTYPE] and [DATEREVIEWASSIG NED] to see how [DATEREVIEWDUE] is populated.
  5. You must Reset the Reference to your Outlook Object Library.
  6. As previously indicated, code in the AfterUpdate() Events of [cboTASKTYPE] and [DATEREVIEWASSIG NED] calculates the correct Value to the [DATEREVIEWDUE] Field. Short of restructuring, you must be very careful which Records in the Sub-Forms are selected before you populate either Field, or the wrong Values will be set in the incorrect Sub-Form Record. This must be fixed by you.
  7. Study the Attachment carefully.
Attached Files
File Type: zip WorkloadAnalysisME.zip (139.5 KB, 107 views)
Nov 2 '09 #16
chhines
18 New Member
ADezii, I have some ?'s with what you've done.
You mentioned you put the Public function in the SendMail Module.
Why there?
I actually wasn't even using the SendMail module yet, and I'm not sure if it will work due to a limitation in Outlook, so will it work if the SendMail module doesn't?

But anyway, why did making it a public function in SendMail Module make it work when it didn't elsewhere as a pub. funct.?
What is the purpose of the line below the End Select that looks like it is referencing the calculation?

When you say cboTASKTYPE and txtDATEREVIEWAS SIGNED are now BOUND, how does this change their relationship in the form?
Where and how can I tell that they are bound and what does it mean?

The event procedures for the After Update prop., why the If Not IsNull?
They should both never be null, one is a combo box which will only allow choices from a specific list and the other is a text box (DATEREVIEWASSI GNED) that has a default value of today's date, which means it will never be null either.

As for the comments in #'s 5 & 6, I’m not sure what you mean about resetting the Outlook reference & how often I'd have to do that.
Also, I was unable to duplicate the error of auto population messing up the calculated DUEDATE based on selecting the wrong field out of sequence.
I'm sure the problem exists as you say, but couldn’t' that be fixed by setting the Tab Order of the form? Thanks again.
Nov 3 '09 #17
ADezii
8,834 Recognized Expert Expert
You mentioned you put the Public function in the SendMail Module.
Why there?
You can put it in the Form's Code Module, but it should be declared as Private and not Public.
I actually wasn't even using the SendMail module yet, and I'm not sure if it will work due to a limitation in Outlook, so will it work if the SendMail module doesn't?
Yes, as long as the Module exists.
But anyway, why did making it a public function in SendMail Module make it work when it didn't elsewhere as a pub. funct.?
Using it as the Control Source was in the wrong context.
What is the purpose of the line below the End Select that looks like it is referencing the calculation?
It's returning the Value of the CalcDueDate() Function to the Field in the Sub-Form.
When you say cboTASKTYPE and txtDATEREVIEWAS SIGNED are now BOUND, how does this change their relationship in the form?
No, their Values are now stored Fields in the Record Source of the Form.
Where and how can I tell that they are bound and what does it mean?
Look at the Control Source Properties.
The event procedures for the After Update prop., why the If Not IsNull?
They should both never be null, one is a combo box which will only allow choices from a specific list and the other is a text box (DATEREVIEWASSI GNED) that has a default value of today's date, which means it will never be null either.
You could enter Value(s) in these Fields,inadvert ently delete them, then move off the Field in which case the Function will crash. A precaution.
As for the comments in #'s 5 & 6, I’m not sure what you mean about resetting the Outlook reference & how often I'd have to do that.
In any Code Window, Tools ==> References. Only done once unless the Outlook Version changes.
Also, I was unable to duplicate the error of auto population messing up the calculated DUEDATE based on selecting the wrong field out of sequence.
I'm sure the problem exists as you say, but couldn’t' that be fixed by setting the Tab Order of the form?
The way it is currently structured, you must be careful to see what Record is selected in each Sub-Form before you enter Values in either one of these Fields. It should probably be a Form/Sub-Form/Sub-Sub Form structure.
Nov 4 '09 #18
NeoPa
32,571 Recognized Expert Moderator MVP
Let me see what I can do with the selected questions (You'll need to wait for ADezii for the others as they are specific to his code).

PS. I started this a long while ago, but got interrupted by a visitor. Unfortunate, but still there are points in here worth reading.
  1. Q. You mentioned you put the Public function in the SendMail Module.
    Why there?
    A. I would guess this was just an available standard module. Public functions are only callable from outside of their own module (EG. from within a SQL string) if they are in a standard code module.
  2. Q. I actually wasn't even using the SendMail module yet, and I'm not sure if it will work due to a limitation in Outlook, so will it work if the SendMail module doesn't?
    A. Yes
  3. Q. But anyway, why did making it a public function in SendMail Module make it work when it didn't elsewhere as a pub. funct.?
    A. See 1 above.
  4. Q. When you say cboTASKTYPE and txtDATEREVIEWAS SIGNED are now BOUND, how does this change their relationship in the form?
    A. Bound controls on a form automatically link their values to the underlying record source. An unbound control shows on the form, but its value is only held there. It is shown but not stored anywhere. Bound controls, on the other hand, reflect the values stored in the record. When moving between records the value changes automatically.
  5. Q. Where and how can I tell that they are bound and what does it mean?
    A. The ControlSource property lets you know if a control is Bound or not. If it is unset, or set to a calculation of some kind, then it is unbound. It is only bound if it contains the name of one of the fields from the recordset.
  6. Q. They should both never be null, one is a combo box which will only allow choices from a specific list and the other is a text box (DATEREVIEWASSI GNED) that has a default value of today's date, which means it will never be null either.
    A. I suspect this is simply defensive programming. Code that covers scenarios that you don't even expect to occur. This is generally considered good.
    NB. Because a control has a default vale does not mean it cannot be Null. That would be false logic. Careful of such assumptions.
  7. Q. As for the comments in #'s 5 & 6, I’m not sure what you mean about resetting the Outlook reference & how often I'd have to do that.
    A. I suspect that ADezii had to reset the Outlook reference in his code as it didn't match yours exactly (for whatever reason). He found a similar reference to use that worked for him. That does mean though, that is different from the one you were using and you probably need to set it back before use. This he cannot do for you as he is missing the relevant reference.
Nov 4 '09 #19
chhines
18 New Member
ADezii and NeoPA. Thanks so much for all your help with fixing this problem, it seems to be working great now!!

More importantly, you've explained the logic to me so I know what is going on and can use the logic in the future if I want to make changes this or add additional items as such.

I have an additional question.

If I want to "grey out" the value of the [DATEREVIEWASSIG NED] & probably even [DATEREVIEWDUE] fields after it is entered for the first time for a particular task, what is the best way to do this? Essentially, after the first person enters a record for a particular task, the review date assigned is and the due date calculated, it should be the same for due date and assigned date for everyone associated with the project, no matter when they start on their portion of it.

Thanks again!
Nov 4 '09 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

9
9194
by: Ben | last post by:
I have two 'Do While Not' statements, that are getting information from the same recordset. If I comment out the first one I can get the results for the second one, and vice-versa. Why is this happening? Is it because it's already at the EOF? If so how do I get it back to the BOF for the 2nd 'Do While Not' statement? '---------------------------------------- 'Create an ADO recordset object Set rs_Report =...
5
4075
by: Rachel Weeden | last post by:
I'm working on an ASP Web application, and am having syntax issues in a WHERE statement I'm trying to write that uses the CInt Function on a field. Basically, I want to select records using criteria of Race, Gender and Crime Code. But the Crime Code field in the table is text, and I cannot change it. I want to use a range of crime codes, so need to convert it to an integer on-the-fly. Here's what I have in my code so far:
9
26843
by: | last post by:
Is it possible to construct a CDO.To statement based on the value of an incoming form drop down list which contains any word such as "ChangeStatus:" How would I construct the IF statement to isolate the 'string' in the incoming variable to allow a branching statement: If Request.form("ChangeStatue") containts the string "Sales Alert" Then '// Else
2
2522
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an Update statement. I have a sample code to reproduce my problem. To simplify the scenario I am trying to use Order related tables to explain a little better the tables i have to work with.
15
2742
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to start at the bottom. What seems to plague many ORM systems is the syntactic confusion and string-manipulation required to build the SQL Statements. If you want to do a Left Outer Join, support nested functions, and a nested conditional clause, you'd...
2
3004
by: deanclowe | last post by:
Hi I have a query that is trying to use a field that is created "AS" based on a case statement like this: SELECT CASE WHEN IPOVH = 'Y' THEN '01' WHEN IPHSI = 'Y' THEN '02' WHEN IPVIS = 'Y' THEN '03' ELSE ' ' END AS CRIT_CODE,
7
11445
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And #11/2/2003# And VehicleID='00000000' And BattID='LKO500HF'. I need to use the records returned to populate text boxes, but the data requires further manipulation. I attempting to use expressions in the control source
19
8379
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without FOR UPDATE, it is fine and no error. I also tried Set objRs = objConn.Execute("SELECT * FROM EMP UPDATE OF EMPNO"), but it still couldn't help. any ideas? I tried to search in the web but couldn't find similar
1
1880
by: hotflash | last post by:
Hi Master CroCrew et All, I am working on a CASE statement to allow different type of searches to search for different type of projects. EVERYTHING WORKS FINE EXCEPT, if the "Any Projects" radio button is checked and if the "All, Complete or Incomplete button is checked, it DISPLAYS everything fine. However, if the "Any Projects" radio button is checked and if the "Complete Projects Only" or "Incomplete Projects Only" button is checked IT...
1
2382
by: robin1983 | last post by:
Dear All, I got stuck in simple problem, I have a two php file one for registration form and one for to check and insert into the table. The problem is that when I get any kind error in validiation the code is working properly but when the condition are fulfilled the code inside the if part is not executing. The following is the code for registration form UserAdd.php <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.