If Then Statement

M

myxmaster

When I select an option I get the following message" Compile Error,
Block If Without End If". I am not sure exactly what is wrong. Can you
please review the following code and tell me where the error is.

Private Sub Filter_Options_AfterUpdate()

If FilterOptions = 1 Then
Me.Filter = "Category = 'Credit'"
Me.FilterOn = True
Else
If FilterOptions = 2 Then
Me.Filter = "Category = 'Check'"
Me.FilterOn = True
Else
If FilterOptions = 3 Then
Me.Filter = "Category = 'Certergy'"
Me.FilterOn = True
Else
If FilterOptions = 4 Then
Me.Filter = "Category = 'Money'"
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End Sub

TIA
 
S

Scott McDaniel

When I select an option I get the following message" Compile Error,
Block If Without End If". I am not sure exactly what is wrong. Can you
please review the following code and tell me where the error is.

You need to End each embedded If statement:

If <something> Then
Else
If <something else> Then
Else
If (something again) Then
End If
End If
End If

However, in your case since your always looking at the value of FilterOptions, you'd be better off using a Select Case
statement:

Select Case FilterOptions
Case 1
Me.Filter = "Category='Credit'"
Case 2
Me.Filter = "Category='Check'"
Case 3
Me.Filter = "Category='Certergy'"
Case 4
Me.Filter= "Category='Money'"
Case Else
End Select

Me.FilterOn = True


Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
M

myxmaster

You need to End each embedded If statement:

If <something> Then
Else
If <something else> Then
Else
If (something again) Then
End If
End If
End If

However, in your case since your always looking at the value of FilterOptions, you'd be better off using a Select Case
statement:

Select Case FilterOptions
Case 1
Me.Filter = "Category='Credit'"
Case 2
Me.Filter = "Category='Check'"
Case 3
Me.Filter = "Category='Certergy'"
Case 4
Me.Filter= "Category='Money'"
Case Else
End Select

Me.FilterOn = True

Scott McDaniel
scott@takemeout_infotrakker.comwww.infotrakker.com

Hi Scott,
I have placed this code in the afterupdate of my Filteroptions group
as a event procedure however nothing happens?
 
S

Scott McDaniel

Hi Scott,
I have placed this code in the afterupdate of my Filteroptions group
as a event procedure however nothing happens?

Where is the value of "FilterOptions" being set? I assumed this was some form of module level variable, or a value set
elsewhere in your code.

Can you verify that your FilterOptions variable actually contains a value? You can do this by setting a Breakpoint in
your code (on the Select Case FilterOptions statement), then running your code and stepping through it (use the F8 key
to step line-by-line through your code).

To view the value of your FilterOptions variable, type this in the Immediate window:

?FilterOptions

and press the Enter key.

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 

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