473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

iif statement involving a check box

2
Hi everyone I'm new to Access, and I'm having issues. I'm trying to get a column in my table to either calculate a length of stay or enter a "0" if a check box indicating never arrived is checked on my form.

I've tried a few different things with no success.

Example:
If [Never Arrived] ="true" Then
[Length of Stay] = "0"

ElseIf [Never Arrived] ="false" Then
[Length of Stay]= "[End of Billing Cycle]-[Begin Billing Date]"

End If

Any thoughts?
Oct 5 '16 #1
3 1362
PhilOfWalton
1,430 Expert 1GB
First thing is you will make life a lot easier for yourself if you don't have spaces in field names.

As you have correctly done, you have to surround then with squre bracketes [Length of Stay], as that is 3 words.

Much better is LengthOfStay. Brackets are then optional and personally I don't put them in, but often Access does.

OK to your question:

True & False are words recognised by Access, so they don't need the quotes round them.
I assume [Length of Stay] is a number and therefor if you put quotes round it you are passing a string to a numeric field. No can do.

Try

Expand|Select|Wrap|Line Numbers
  1.  
  2. If [Never Arrived] = True Then
  3.     [Length of Stay] = 0
  4. Else 
  5. [Length of Stay]= "[End of Billing Cycle]-[Begin Billing Date]"
Oct 5 '16 #2
PhilOfWalton
1,430 Expert 1GB
Sorry, pressed the Tab key and the message went before I had finished.

Try

Expand|Select|Wrap|Line Numbers
  1. If [Never Arrived] = True Then
  2.     [Length of Stay] = 0
  3. Else 
  4.    [Length of Stay]= [End of Billing Cycle] - [Begin Billing Date]
  5. End If
  6.  
Much cleaner is without the spaces in the field names and just as readable

Expand|Select|Wrap|Line Numbers
  1. If NeverArrived = True Then
  2.     LengthOfStay = 0
  3. Else 
  4.    LengthOfStay= EndOfBillingCycle - BeginBillingDate
  5. End If
  6.  
Phil
Oct 5 '16 #3
jadira
2
Thanks I actually figured it out before I got a reply. I used a simple function in the table.

IIf([Never Arrived],0,([End of Billing Cycle]-[Begin Billing Date]))

I was over complicating things.
Oct 6 '16 #4

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

Similar topics

1
by: Swaq | last post by:
Or, at least, I find it complicated :-) Hopefully it is not that hard but here goes: I have two tables: Persons and Relations Persons contain personal data such as person_ID, name, adresse,...
7
by: Altemir | last post by:
I want to create an UPDATE statement that updates a value in a table in database A based on the results of an inner join between tables each residing in deifferent databases. What is the correct...
14
by: Ørjan Langbakk | last post by:
I have a form where the user has the possibility to enclose his name. email, address and phonenumber. I want to be able to check if some of the fields are filled - at least one. This is so that...
6
by: LB79 | last post by:
Hello - Im having a few problems with my IIF statement. I want the IIF statement to check a field and then return a value from a choice of 2 other fields depending on its contents. The below is...
6
by: Geoff Berrow | last post by:
Message-ID: <9d87b477-d2aa-442d-b727-927be1e3386c@y38g2000hsy.googlegroups.comfrom chadlupkes contained the following: The comp.lang.php crystal ball is broken again. What's the problem? ...
13
by: curious80237 | last post by:
In Access 2003: A table with four yes/no fields is part of a query used as data source for a report. The yes/no fields show in the datasheet and the report as checkboxes; the default value of the...
7
by: hatch | last post by:
The project I am working on has to have start and stop buttons on a form and a label to show the eslaped time once the start button is pushed. The elapsed tome should stop when the stop button is...
3
by: JasonWinchester | last post by:
Hi, all I'm having trouble figuring out how to use an if-then statement to check whether or not a variable is pointing to a look-up column. What I have is a form that contains a combobox and a...
0
by: Madiha Ahmed | last post by:
Can I use If Exists statement statement in vb.net to check if a particular filed exists in my MS Access database ?
0
by: billoo97 | last post by:
I have tried the following with a couple of variations but I continue to get errors. Any way to get this fixed. DB2 10.1 (DB2 for z/OS V10) For the following ------------------------------ MERGE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.