Select Case help needed

J

Jim

I'm using a Select Case statement to check the value of 24 checkboxes on a
form. If true for each case, run the related query. It seems to be running
the first query it comes to and not continuing to check the rest. Below is
sample code for the first 4 checkboxes. Can anyone help?

Select Case True
Case Me.chkQCT01.value = True
DoCmd.OpenQuery "AccessMWapp", acNormal, acEdit
Case Me.chkQCT02.value = True
DoCmd.OpenQuery "AccessSEapp", acNormal, acEdit
Case Me.chkQCT03.value = True
DoCmd.OpenQuery "AccessSWapp", acNormal, acEdit
Case Me.chkQCT04.value = True
DoCmd.OpenQuery "AccessWapp", acNormal, acEdit
End Select

Thanks,
Jim
 
D

Daryl S

Jim -

That is what a SELECT CASE statement does. It finds the first match and
ignores the rest.

If you want to run a query for every TRUE, then just use IF statements, like
this:

If Me.chkQCT01.value Then
DoCmd.OpenQuery "AccessMWapp", acNormal, acEdit
End If
If Me.chkQCT02.value Then
DoCmd.OpenQuery "AccessSEapp", acNormal, acEdit
End If
If Me.chkQCT03.value Then
DoCmd.OpenQuery "AccessSWapp", acNormal, acEdit
End If
If Me.chkQCT04.value Then
DoCmd.OpenQuery "AccessWapp", acNormal, acEdit
End If
 
D

Dirk Goldgar

Jim said:
I'm using a Select Case statement to check the value of 24 checkboxes on a
form. If true for each case, run the related query. It seems to be
running
the first query it comes to and not continuing to check the rest. Below
is
sample code for the first 4 checkboxes. Can anyone help?

Select Case True
Case Me.chkQCT01.value = True
DoCmd.OpenQuery "AccessMWapp", acNormal, acEdit
Case Me.chkQCT02.value = True
DoCmd.OpenQuery "AccessSEapp", acNormal, acEdit
Case Me.chkQCT03.value = True
DoCmd.OpenQuery "AccessSWapp", acNormal, acEdit
Case Me.chkQCT04.value = True
DoCmd.OpenQuery "AccessWapp", acNormal, acEdit
End Select


The function of the Select Case statement is to resolve to at most one --
and only one -- case. So if you have a series of cases, only the first one
whose condition evaluates as True will be executed.

If more than one of your check boxes could be True, then don't use Select
Case. Use a series of "If ... End If" blocks instead:

If Me.chkQCT01 = True Then
DoCmd.OpenQuery "AccessMWapp", acNormal, acEdit
End If
If Me.chkQCT02 = True Then
DoCmd.OpenQuery "AccessSEapp", acNormal, acEdit
End If
If Me.chkQCT03 = True Then
DoCmd.OpenQuery "AccessSWapp", acNormal, acEdit
End If
If Me.chkQCT04 = True Then
DoCmd.OpenQuery "AccessWapp", acNormal, acEdit
End If
 

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