Nesting If Statements Question

N

nxqviet

Hi all,

I have a series of check boxes on a form and a button. When this botton
is clicked, a series of Append queries will be ran depending on the
value of the check boxes.

For example, if check box 1 is checked, Append query 1 will run
if check box 2 is checked, Append query 2 will run
if check box 3 is checked, Append query 3 will run
But if check box 1 AND 2 and 3 were checked, all 3 Append Queries
should run.
Or when only 2 were check, 2 respective queires should run.

This is very simple, but I have about 10 check boxes.

So I have this code:

If checkbox1.value = true Then
docmd......to run append query1
Else
If checkbox2.value = true Then
docmd......to run append query2
Else
If checkbox3.value = true Then
docmd......to run append query3
Else
If checkbox4.value = true Then
docmd......to run append query4
.....
End If
End If
End If
End If
.....

With this code, If the first check box (checkbox1) is False, would the
code continue on checking the second and third and so on? And If that
first box is True in stead, would it still continue on checking the
second and third ... ?

How should I write a code to accomplish this task?

Please help and Thank you for your time,


V_
 
B

Brendan Reynolds

Do I understand correctly, that you want the second query to run if check
box 2 is checked, regardless of whether checkbox 1 is checked or not? If so,
the solution is to *not* nest the tests, but to execute them sequentially,
like so ...

If checkbox1.Value = True Then
CurrentProject.Connection.Execute qryOne
End If

If checkbox2.Value = True Then
CurrentProject.Connection.Execute qryTwo
End If
 
N

nxqviet

Yes, you had it correct.
Ahhhh, simple solution. With your code, queryOne will not be execute if
checkbox 1 is not checked and so on for all other checkboxes right?

Thanks Brendan

Viet
 
J

James A. Fortune

nxqviet said:
Hi all,

I have a series of check boxes on a form and a button. When this botton
is clicked, a series of Append queries will be ran depending on the
value of the check boxes.

For example, if check box 1 is checked, Append query 1 will run
if check box 2 is checked, Append query 2 will run
if check box 3 is checked, Append query 3 will run
But if check box 1 AND 2 and 3 were checked, all 3 Append Queries
should run.
Or when only 2 were check, 2 respective queires should run.

This is very simple, but I have about 10 check boxes.

So I have this code:

If checkbox1.value = true Then
docmd......to run append query1
Else
If checkbox2.value = true Then
docmd......to run append query2
Else
If checkbox3.value = true Then
docmd......to run append query3
Else
If checkbox4.value = true Then
docmd......to run append query4
.....
End If
End If
End If
End If
....

With this code, If the first check box (checkbox1) is False, would the
code continue on checking the second and third and so on? And If that
first box is True in stead, would it still continue on checking the
second and third ... ?

How should I write a code to accomplish this task?

Please help and Thank you for your time,


V_

Don't nest them for that situation.

If checkbox1.Value = true Then
docmd.......to run append query1
End If
If checkbox2.Value = true Then
docmd.......to run append query2
End If
....

Also see the Help file about using the RecordsAffected Property or the
StillExecuting Property in conjunction with an Execute (Database object
method).

James A. Fortune
(e-mail address removed)

(not referring to you):
You know you're dealing with a computer illiterate when...

They keep a CD in the CD-ROM drive so the coffee cup won't slip through.

They think splash page has something to do with toilet paper.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top