Select Case help needed

  • Thread starter Thread starter Jim
  • Start date Start date
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
 
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
 
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
 
Back
Top