We help IT Professionals succeed at work.

# updating a field in a subform with a calculation from 2 other fields

on
Access 2010   vba

I'm updating a field in a subform with a calculation from 2 other fields.

Is there an easier way to write this  code ?

' =====================================
Dim g As String
Dim j As String

g = Me!RENEWAL_ESCALATED_PRICE_INCREASE_FRM
j = Me!ESTIMATED_REVENUE_IMPACT_FRM

' ============================================
'  < 4%
If g < 4 And j < 250 Then
Me!ACTION_NEEDED_FRM = "Update Quote"
End If
' < 4%
If g < 4 And j > 250 And j < 1000 Then
Me!ACTION_NEEDED_FRM = "RSVP/Director Approval"
End If
' < 4%
If g < 4 And j > 1000 Then
Me!ACTION_NEEDED_FRM = "FVP Approval"
End If

' =========================================
'  >4  and < 8%
If g > 4 And g < 8 And j < 250 Then
Me!ACTION_NEEDED_FRM = "Update Quote"
End If

'  >4  and < 8%
If g > 4 And g < 8 And j > 250 And j < 1000 Then
Me!ACTION_NEEDED_FRM = "RSVP/Director Approval"
End If

'  >4  and < 8%
If g > 4 And g < 8 And j > 1000 Then
Me!ACTION_NEEDED_FRM = "RSVP/Director Approval"
End If

' ===========================================
'  > 8%
If g > 8 And j < 250 Then
Me!ACTION_NEEDED_FRM = "Update Quote"
End If
' > 8%
If g > 8 And j > 250 And j < 1000 Then
Me!ACTION_NEEDED_FRM = "Update Quote"
End If
' > 8%
If g > 8 And j > 1000 Then
Me!ACTION_NEEDED_FRM = "Update Quote"
End If
Comment
Watch Question

## View Solution Only

Distinguished Expert 2017
Commented:
A Select Case would be clearer and less redundant.  It also looks like j should be the primary test.

When j < 250, g is irrelevant

There is an error also since if the value of j is exactly 250 or g = 8, they doesn't fit any criteria.

Please review this carefully since I modified it to handle 250:
``````Select Case j
Case < 250
Me.ACTION_NEEDED_FRM = "Update Quote"
Case >= 250 and < 1000
If g > 8 Then
Me.ACTION_NEEDED_FRM = "Update Quote"
Else
Me.ACTION_NEEDED_FRM = "RSVP/Director Approval"
End If
Case Else
Select Case g
Case > 8
Me.ACTION_NEEDED_FRM = "Update Quote"
Case < 4
Me.ACTION_NEEDED_FRM = "FVP Approval"
Case Else
Me.ACTION_NEEDED_FRM = "RSVP/Director Approval"
End Select
End Select
``````

Commented:
Thanks pat.as always
Distinguished Expert 2017

Commented:
You're welcome.  Please test carefully since your original code was not processing certain values at all.

Commented:
pat , sorry to get back on this:

getting an error on this line

Case >= 250 and < 1000  from above

Thanks
fordraiders
Distinguished Expert 2017

Commented:
You might want to share the error message/number.  Is it a compile error or a runtime error?