473,574 Members | 2,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If...Then...Els e

Hello all,

I have 13 check boxes on a form.

I am trying to check all the check boxes to determine if they are true or false when I close the form.

At present only the first IF...Then...Els e works and then Exits the Sub.

Example:

If Me.First = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If

If Me.Second = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If

If Me.Third = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If
....
Total of 13 check Boxes to be checked on Form Close.

I have tried with only one End If statement at the end to no luck.

Thank you for your help.

Glen
Nov 12 '05 #1
19 8208
Mal
If this is how your code appears then you really don't which IF statement is evaluating to true...since all of them are affecting the same me.fieldname
I'm not sure why you would want a check box AND a field name since added only YES to the field is the same as having a checkbox.

If its for a report/list somewhere else then handle that then.
ie. a control on a report can be set to display whatever text you like based on the value of the text box.

If this was just an example of code...not the real deal...then look for an exit sub or something within the first IF

With a little more explanation of what you want to achieve, and probably a cut & paste of the actual code...you will more than likely get a better answer

HTH
Mal.
PS: IF this really is how your code works....start changing all the names...FIRST, SECOND etc. are all ACCESS reserved words and may cause you a lot of grief later.
"GMKS" <gm**@shaw.ca > wrote in message news:8GbYb.5324 33$X%5.241805@p d7tw2no...
Hello all,

I have 13 check boxes on a form.

I am trying to check all the check boxes to determine if they are true or false when I close the form.

At present only the first IF...Then...Els e works and then Exits the Sub.

Example:

If Me.First = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If

If Me.Second = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If

If Me.Third = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If
...
Total of 13 check Boxes to be checked on Form Close.

I have tried with only one End If statement at the end to no luck.

Thank you for your help.

Glen

Nov 12 '05 #2
I will explain in more detail.

This is a sports registration database for Disabled and Ablebodied members. The check boxes are there to determine the type of disability if any for those registering. As there could be family members of disabled members registering in this program that are not disabled, any check box = true would place the Disabled name in the Disability field else they would be classed as Ablebodied.

Private Sub Form_Close()

On Error GoTo PROC_ERR

If Me.Blind = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If

If Me.Deaf = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If
....
Me.Refresh

I hope this helps.

I have looked at the If..Then...Else including the ElseIf but I have had nothing that will go through the complete list.

I think I need to run a Do Until Record set or Block If statement but do not know how.

Glen
"Mal" <me@myHome.co m> wrote in message news:10******** *****@corp.supe rnews.com...
If this is how your code appears then you really don't which IF statement is evaluating to true...since all of them are affecting the same me.fieldname
I'm not sure why you would want a check box AND a field name since added only YES to the field is the same as having a checkbox.

If its for a report/list somewhere else then handle that then.
ie. a control on a report can be set to display whatever text you like based on the value of the text box.

If this was just an example of code...not the real deal...then look for an exit sub or something within the first IF

With a little more explanation of what you want to achieve, and probably a cut & paste of the actual code...you will more than likely get a better answer

HTH
Mal.
PS: IF this really is how your code works....start changing all the names...FIRST, SECOND etc. are all ACCESS reserved words and may cause you a lot of grief later.
"GMKS" <gm**@shaw.ca > wrote in message news:8GbYb.5324 33$X%5.241805@p d7tw2no...
Hello all,

I have 13 check boxes on a form.

I am trying to check all the check boxes to determine if they are true or false when I close the form.

At present only the first IF...Then...Els e works and then Exits the Sub.

Example:

If Me.First = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If

If Me.Second = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If

If Me.Third = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If
...
Total of 13 check Boxes to be checked on Form Close.

I have tried with only one End If statement at the end to no luck.

Thank you for your help.

Glen
Nov 12 '05 #3
"GMKS" <gm**@shaw.ca > wrote in
news:g1dYb.5330 06$X%5.299520@p d7tw2no:
I will explain in more detail.

This is a sports registration database for Disabled and
Ablebodied members. The check boxes are there to determine
the type of disability if any for those registering. As there
could be family members of disabled members registering in
this program that are not disabled, any check box = true would
place the Disabled name in the Disability field else they
would be classed as Ablebodied.

Private Sub Form_Close()

On Error GoTo PROC_ERR

If Me.Blind = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If

If Me.Deaf = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If
...
Me.Refresh

I hope this helps.

I have looked at the If..Then...Else including the ElseIf but
I have had nothing that will go through the complete list.

I think I need to run a Do Until Record set or Block If
statement but do not know how.

I know what your problem is!!!!!!
It is the ELSE:

modify the location of me.disability = "ablebodies " to place it
above your IF statements and all will be right
On Error GoTo PROC_ERR

If Me.Blind = True Then
Me.Disability = "Disabled"
End If

If Me.Deaf = True Then
Me.Disability = "Disabled"
End If
...
Me.Refresh
Why? In your code, if someone is blind but not deaf, watch what
happens: Blind = true, therefore you set disability to disabled,
then you evaluate Deaf = true, and it is not, so you set disability
= "ablebodied ". That's not what you want. So start with
"ablebodied ", and only make the if statements make the change one
way, to "disabled"

By the way, I don't know whether ELSE: is a valid construct, it has
always been else on one line, the statement to execute on the
following lines, and the end if on a line underneath. .
Bob Q
Nov 12 '05 #4
RE/
On Error GoTo PROC_ERR

If Me.Blind = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If

If Me.Deaf = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If


With Me
If ((.Blind=True) OR (.Deaf=True) OR (.Quad=True) OR (.Bald=True)) Then
.Disabled=True
Else
.Disabled=False
End If
End With
--
PeteCresswell
Nov 12 '05 #5
RE/
If Me.First = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If


In the example, "Else:" has become a paragraph name by virtue of the colon.
--
PeteCresswell
Nov 12 '05 #6
Thank you Pete

I have adjusted your example to the following:

With Me
If ((.Blind = True) _
Or (.Deaf = True) _
Or (.Paraplegic = True) _
Or (.Quadriplegic = True) _
Or (.Amputee = True) _
Or (.Disability = True) _
Or (.Developmental lyDelayed = True) _
Or (.LearningDisab led = True) _
Or (.BrainInjury = True) _
Or (.SteelRod = True) _
Or (.CerebralPalsy = True) _
Or (.Shunt = True) _
Or (.Braces = True) _
Or (.SpinaBifida = True)) Then
.Disability = "Disabled"
Else
.Disability = "Ablebodied "
End If
End With

I added a breakpoint to view the results.

With a single check box clicked, the value of that single check boxes is -1
and all is well but with no check boxes clicked the value of each = 0, but
the final result is .Disability = "Disabled" where it should be .Disability
= "Ablebodied ".

Is there something missing?

Glen

"(Pete Cresswell)" <x@y.z> wrote in message
news:f2******** *************** *********@4ax.c om...
RE/
On Error GoTo PROC_ERR

If Me.Blind = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If

If Me.Deaf = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If


With Me
If ((.Blind=True) OR (.Deaf=True) OR (.Quad=True) OR (.Bald=True)) Then
.Disabled=True
Else
.Disabled=False
End If
End With
--
PeteCresswell

Nov 12 '05 #7
"(Pete Cresswell)" <x@y.z> wrote in
news:f2******** *************** *********@4ax.c om:
RE/
On Error GoTo PROC_ERR

If Me.Blind = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If

If Me.Deaf = True Then
Me.Disability = "Disabled"
Else: Me.Disability = "Ablebodied "
End If


With Me
If ((.Blind=True) OR (.Deaf=True) OR (.Quad=True) OR
(.Bald=True)) Then
.Disabled=True
Else
.Disabled=False
End If
End With


Er, why not:

With Me
.Disabled = (!Blind) OR (!Deaf) OR (!Quad) OR (!Bald)
End With

Why use an IF/THEN/ELSE to test Boolean values that are then used to
set a Boolean value?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #8
On Tue, 17 Feb 2004 01:45:09 GMT, "(Pete Cresswell)" <x@y.z> wrote:
RE/
If Me.First = True Then
Me.FieldName = "Yes"
Else: Me.FieldName = "No"
End If


In the example, "Else:" has become a paragraph name by virtue of the colon.


A "paragraph name?" Do you mean a Label?

Test the wonders of VB syntax :-)

If False Then
Call MsgBox("True")
Else: Call MsgBox("False") : Call MsgBox("False again")
Call MsgBox("... and False")
End If

But you will get a compiler error message "Else without If" here:

If True Then Call MsgBox("True")
Else
Call MsgBox("False")
End If

And check out these:

If True Then Call MsgBox("True"): Call MsgBox("True again")
If True Then: Call MsgBox("True"): Call MsgBox("True again")

This means that the ":" in all these cases is a Statement separator.
You cannot have a label named "Else:" in VB, since "Else" is a
reserved word.

With kind regards
Matthias Kläy
--
www.kcc.ch
Nov 12 '05 #9
With Me

If .Blind And .Deaf And .Paraplegic And .Quadriplegic And .Amputee _
And .Disability And .Developmentall yDelayed And .LearningDisabl ed _
And .BrainInjury And .SteelRod And .CerebralPalsy And .Shunt _
And .Braces = True And .SpinaBifida Then

.Lucky = False

End If

End With
Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
603
by: pbdev | last post by:
Hello, I am new to mysql and am trying to write the following sql statement. SELECT item, action, due_date, category FROM maint_due WHERE due_date Between Now() AND IF Select dayofweek(now()) = 1 Then (Now()+6) Else If Select dayofweek(now()) = 2 Then
1
3345
by: avital | last post by:
Hi, I have a sql query with cases. I need to add a condition that if hasamafactor=5 then display only cases m11-m14 else display the rest. Of course sum ( kamut) as total4mosad has to be only for the relevant cases and not all of them. CREATE PROCEDURE .
2
2469
by: misscrf | last post by:
I have a search form that is great. I have modified it in such a way, that when search results come up I can bring it back to a useful spot, say an entry form or a report. Here is my lemon ( hoping someone can help me make lemonade!) I have this form implemented with my Candidate entry form, as a find. click the find button, search,...
11
17399
by: Kai Bohli | last post by:
Hi all ! I need to translate a string to Ascii and return a string again. The code below dosen't work for Ascii (Superset) codes above 127. Any help are greatly appreciated. protected internal string StringToAscii(string S) { byte strArray = Encoding.UTF7.GetBytes(S); string NewString = Encoding.UTF7.GetString(strArray);
4
1913
by: louise raisbeck | last post by:
I have this scenario (simplified) function addnewdata () { check for partial match already in db for information entered by user if (partialmatch succeeds) { open new window aspx page (using javascript) with a datagrid of these partial match records (by doing a sqlcommand using some query string values taken from opener data entered) ***...
3
3927
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the right direction about what I am not doing correctly? 1.. Write an If Then Else statement that displays the string "Pontiac" in the CarMakeLabel...
15
5317
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run...
14
4184
by: lawjake | last post by:
I am having a dispute at work over endifs, and cannot find any treatise on this. So I am hoping that I can get a lot of correspondece confirming my belief. Here it is: I believe the following: (1)If a language has an "endif", then every "if" statement requires an endif, and (2) every "endif" goes with the last "if". For example,
4
2480
by: lutzkac | last post by:
Hi Everyone, I am in a bit of a pickle and need some expert advice. I have a db in access. I am trying to create a query with fields from the tables. In my query I need to take the value of one field and depending on what the value is pull a date from other fields. I have tried a IIF and it errors. Tried to write an if-then-else function ( which...
0
7815
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...
0
7738
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8114
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...
0
6477
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...
1
5634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3766
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2254
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
1
1359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1076
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...

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.