PDA

View Full Version : After Update event correct If statement



stevo
07-20-2013, 02:03 AM
how do i write the following access vba After update() code, so when ever a value between 40 and 49, 50 and 60 etc is entered into
txtspeed form field it will display the appiciable txtfine Value for that number. i.e 44 = 350, 55 = 750
The following code works for 40, 50, 60 and 70 but i can't get it to work using the following >= 40 =< 50 as a range value.


Private Sub txtspeed_AfterUpdate()

If txtspeed.Value = 40 Then
txtFine.Value = 350
ElseIf txtspeed.Value = 50 Then
txtFine.Value = 750
ElseIf txtspeed.Value = 60 Then
txtFine.Value = 1000
ElseIf txtspeed.Value = 70 Then
txtFine.Value = 1500

End If
End Sub

SamT
07-20-2013, 05:37 AM
Private Sub txtspeed_AfterUpdate()

If txtspeed.Value = 40 Then
txtFine.Value = 350
ElseIf txtspeed.Value = 50 Then
txtFine.Value = 750
ElseIf txtspeed.Value = 60 Then
txtFine.Value = 1000
ElseIf txtspeed.Value = 70 Then
txtFine.Value = 1500

TxtSpeed = TxtFine

End If
End Sub
"Select Case" is better than multiple "If"sPrivate Sub txtspeed_AfterUpdate()
'TxtFine must be a UserForm Box

Select Case TxtSpeed
Case Is >= 70
TxtFine.Value = 1500
Case Is >= 60
TxtFine.Value = 1000
Case Is >= 50
TxtFine.Value = 750
Case Is >= 40
TxtFine.Value = 350
Case Else
'Up to you
End Select

'To show TxtFine in the TxtSpeed box
'TxtSpeed = TxtFine
End If
End Sub

stevo
07-20-2013, 06:21 AM
Thanks SamT
I got a small error when I pasted the code, but all it needed was to delete the line near the bottom with END If.
Works great and thanks again for the pointing me in the right direction as I habe just started using vba with access:friends: :friends: