Help simplifying If statement

G

gigglin''''me

Can this be simplified?

Private Sub ARC50K
If [PoolCloseDate] > Now() And Me.ckbProgramRate = False And _
Me.grpProgramOptions.Value = 6 And [RateRequested] >= 4.4 Then
[MatrixID] = 137
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = True And _
(Me.grpProgramOptions.Value = 6 Or Me.grpProgramOptions.Value = 3)
Then
[MatrixID] = 153
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = True And _
Me.grpProgramOptions.Value = 2 Then
[MatrixID] = 154
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = False And _
Me.grpProgramOptions.Value = 1 And Me.txtRateRequested >= 0 Then
[MatrixID] = 165
Else
[MatrixID] = 147
End If

End Sub

Thank you.
Robin
 
B

BruceM

If Me.PoolCloseDate > Now() Then
If Me.ckbProgramRate = False Then
If Me.grpProgramOptions = 6 And _
Me.RateRequested >= 4.4 Then
Me.MatrixID = 137
Else
If Me.grpProgramOptions = 1 And _
Me.RateRequested >= 0 Then
Me.MatrixID = 165
End If
End If
Else
If Me.grpProgramOptions = 6 Or _
Me.grpProgramOptions = 3 Then
Me.MatrixID = 153
Else
If Me.grpProgramOptions.Value = 2 Then
Me.MatrixID = 154
End If
End If
End If
Else
Me.MatrixID = 147
End If

I think it's all there. The general idea is that you don't test the same
condition more than is necessary. All of your Ifs started by seeing if
PoolCloseDate > Now, so that is tested once. Similarly, ckbProgramRate can
be only True or False, so it is tested only once.

You were inconsistent in how you named fields and/or controls, so I made
some changes to address that. Also, I assumed txtRateRequested and
RateRequested represent the same value.

Note that MatrixID will be 147 whenever the PoolCloseDate < Now, or if it is
Now and the other specific combinations do not match. Date() may be
better than Now() unless you mean to include the time of day.

gigglin''''me said:
Can this be simplified?

Private Sub ARC50K
If [PoolCloseDate] > Now() And Me.ckbProgramRate = False And _
Me.grpProgramOptions.Value = 6 And [RateRequested] >= 4.4 Then
[MatrixID] = 137
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = True And _
(Me.grpProgramOptions.Value = 6 Or Me.grpProgramOptions.Value = 3)
Then
[MatrixID] = 153
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = True And _
Me.grpProgramOptions.Value = 2 Then
[MatrixID] = 154
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = False And _
Me.grpProgramOptions.Value = 1 And Me.txtRateRequested >= 0 Then
[MatrixID] = 165
Else
[MatrixID] = 147
End If

End Sub

Thank you.
Robin
 
G

gigglin''''me

Thank you so much and I greatly appreciate your feedback.

~Robin

BruceM said:
If Me.PoolCloseDate > Now() Then
If Me.ckbProgramRate = False Then
If Me.grpProgramOptions = 6 And _
Me.RateRequested >= 4.4 Then
Me.MatrixID = 137
Else
If Me.grpProgramOptions = 1 And _
Me.RateRequested >= 0 Then
Me.MatrixID = 165
End If
End If
Else
If Me.grpProgramOptions = 6 Or _
Me.grpProgramOptions = 3 Then
Me.MatrixID = 153
Else
If Me.grpProgramOptions.Value = 2 Then
Me.MatrixID = 154
End If
End If
End If
Else
Me.MatrixID = 147
End If

I think it's all there. The general idea is that you don't test the same
condition more than is necessary. All of your Ifs started by seeing if
PoolCloseDate > Now, so that is tested once. Similarly, ckbProgramRate can
be only True or False, so it is tested only once.

You were inconsistent in how you named fields and/or controls, so I made
some changes to address that. Also, I assumed txtRateRequested and
RateRequested represent the same value.

Note that MatrixID will be 147 whenever the PoolCloseDate < Now, or if it is
Now and the other specific combinations do not match. Date() may be
better than Now() unless you mean to include the time of day.

gigglin''''me said:
Can this be simplified?

Private Sub ARC50K
If [PoolCloseDate] > Now() And Me.ckbProgramRate = False And _
Me.grpProgramOptions.Value = 6 And [RateRequested] >= 4.4 Then
[MatrixID] = 137
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = True And _
(Me.grpProgramOptions.Value = 6 Or Me.grpProgramOptions.Value = 3)
Then
[MatrixID] = 153
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = True And _
Me.grpProgramOptions.Value = 2 Then
[MatrixID] = 154
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = False And _
Me.grpProgramOptions.Value = 1 And Me.txtRateRequested >= 0 Then
[MatrixID] = 165
Else
[MatrixID] = 147
End If

End Sub

Thank you.
Robin
 
B

BruceM

You're welcome. Good luck with the project.

gigglin''''me said:
Thank you so much and I greatly appreciate your feedback.

~Robin

BruceM said:
If Me.PoolCloseDate > Now() Then
If Me.ckbProgramRate = False Then
If Me.grpProgramOptions = 6 And _
Me.RateRequested >= 4.4 Then
Me.MatrixID = 137
Else
If Me.grpProgramOptions = 1 And _
Me.RateRequested >= 0 Then
Me.MatrixID = 165
End If
End If
Else
If Me.grpProgramOptions = 6 Or _
Me.grpProgramOptions = 3 Then
Me.MatrixID = 153
Else
If Me.grpProgramOptions.Value = 2 Then
Me.MatrixID = 154
End If
End If
End If
Else
Me.MatrixID = 147
End If

I think it's all there. The general idea is that you don't test the same
condition more than is necessary. All of your Ifs started by seeing if
PoolCloseDate > Now, so that is tested once. Similarly, ckbProgramRate
can
be only True or False, so it is tested only once.

You were inconsistent in how you named fields and/or controls, so I made
some changes to address that. Also, I assumed txtRateRequested and
RateRequested represent the same value.

Note that MatrixID will be 147 whenever the PoolCloseDate < Now, or if it
is
Now and the other specific combinations do not match. Date() may be
better than Now() unless you mean to include the time of day.

gigglin''''me said:
Can this be simplified?

Private Sub ARC50K
If [PoolCloseDate] > Now() And Me.ckbProgramRate = False And _
Me.grpProgramOptions.Value = 6 And [RateRequested] >= 4.4 Then
[MatrixID] = 137
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = True And _
(Me.grpProgramOptions.Value = 6 Or Me.grpProgramOptions.Value =
3)
Then
[MatrixID] = 153
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = True And _
Me.grpProgramOptions.Value = 2 Then
[MatrixID] = 154
ElseIf [PoolCloseDate] > Now() And Me.ckbProgramRate = False And _
Me.grpProgramOptions.Value = 1 And Me.txtRateRequested >= 0 Then
[MatrixID] = 165
Else
[MatrixID] = 147
End If

End Sub

Thank you.
Robin
 

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

Similar Threads


Top