Select Case Me!togMonth
Case Me!togMonth = True
Me.Visible = False
DoCmd.OpenReport "rptMonth", _
View:=acViewPreview, _
OpenArgs:=Me.name
Exit Sub
Case Me!togMonth = False
DoCmd.OpenForm _
formName:="popPrint", _
View:=acNormal, _
Windowmode:=acDialog
'picked your report so...
If IsNull(TempVars!Report) Then
Exit Sub
ElseIf TempVars!Report = "rptWeek" Then
Me.Visible = False
GroceryListTable
End If
In the above code, debug returns Me!togMonth as false and yet the code continues to the next line instead of going to Me.togMonth=False. Am I doing something obviously wrong?
With only two options, you could just use an If/Then/Else block. I think the reason your Select Case block is not working is because it's probably not constructed correctly.
Try altering your CASE statement - you have said
Select Case Me!togMonth
Then have
Case Me!togMonth = True
should you not just be testing CASE True and later Case False
Clarity to you was in this case overkill (of syntax) and for literal-minded computer programs like the VBA compiler, overkill kills.
However, once you look at the correct syntax, you should realize that your expressions would not evaluate correctly. This is what you REALLY were evaluating. I'm going to add two lines of code to show what REALLY happens with that statement.
Code:
Select Case Me!togMonth
Case Me!togMonth = True
X = 1
Case Me!togMonth = False
X = 2
end select
Your CASE statements present an expression following keyword CASE, but CASE wants a single scalar value, not an expression. That means it must evaluate the expressions to form those scalars. This conversion is a key point.
Let's execute the SELECT CASE statement, where Me!togMonth is either TRUE or FALSE (not counting David's point about the NULL option.) Then let's see what happens.
In the case where Me!togMonth was TRUE, then the first CASE statement (CASE Me!togMonth=TRUE) resolves to CASE TRUE. So since Me!togMonth was TRUE, X=1 will be executed. The other CASE statement (Me!togMonth = False) resolves to CASE FALSE but that doesn't matter because the CASE ladder only executes the first matching CASE value statement anyway, and we already hit that.
In the case where Me!togMonth was FALSE, the first CASE statement (CASE Me!togMonth=TRUE) resolves to CASE FALSE. Since Me!togMonth was FALSE, X=1 will be executed. The other CASE statement (CASE Me!togMonth=FALSE) resolves to CASE TRUE, which again doesn't mater because the CASE ladder already found its matching value.
Which means in a nutshell that you would never have executed the segment where I set X=2.
In the expression:
SomeField = True
VBA will interpret this as True as long as SomeField is not null. That is why, the first case is being selected. You are not checking the value of SomeField as the code is written, you are checking the value of "SomeField = True" @MajP gave you the correct syntax.