Currency validation rules In Forms HELP (ASAP)

After i copy and pasted the code, it shown same as below

Private Sub Salary_BeforeUpdate(Cancel As Integer)
Dim blnError As Boolean
Dim strJob As String

Select Case Me.Job
Case "Engineer"
If Me.Salary Not Between 30000 And 40000 Then
blnError = True
strJob = "Engineer"
End If

Case "Trainee"
If Me.Salary Not Between 20000 And 30000 Then
blnError = True
strJob = "Trainee"
End If

Case "Clerk"
If Me.Salary Not Between 0 And 20000 Then
blnError = True
strJob = "Clerk"
End If
End Select

If blnError Then
Cancel = True
MsgBox "You have entered a salary for the " & strJob & vbCrLf & _
"which is out of the appropriate range. Please try again!, vbExclamation, "Salary Entry Error"
Exit Sub
End If

End Sub

That means the coding got problem . May you correct it?
 
Sorry, I thought the BETWEEN would work. So, since it won't - use this:
Code:
Private Sub Salary_BeforeUpdate(Cancel As Integer)
Dim blnError As Boolean
Dim strJob As String

Select Case Me.Job
   Case "Engineer"
     If Me.Salary >= 30000 And Me.Salary <= 40000 Then
        blnError = True
        strJob = "Engineer"
    End If

Case "Trainee"
     If Me.Salary >= 20000 And Me.Salary <= 30000 Then
        blnError = True
        strJob = "Trainee"
    End If

Case "Clerk"
    If Me.Salary >= 0 And Me.Salary >= 20000 Then
        blnError = True
        strJob = "Clerk"
    End If
End Select

If blnError Then
   Cancel = True
   MsgBox "You have entered a salary for the " & strJob & vbCrLf & _
"which is out of the appropriate range. Please try again!", vbExclamation, "Salary Entry Error"
   Exit Sub
End If

End Sub
 
You placed the code into the Form Module where the Salary Text Box resides....but did you also ensure that the Before Update event property box contains:

[Event Procedure]

.
 
lol, cant also =.= Wait, my Job i set it as a COMBO box, that i can choose for "engineer","trainee",and "clerk" in a list. Is this the problem that all the code wont work?
 
Wait, my Job i set it as a COMBO box, that i can choose for "engineer","trainee",and "clerk" in a list. Is this the problem that all the code wont work?
That COULD be since your value may be an ID number and not the text value you expect. Add this to the code, at the top, to see what you are getting for a value:

Msgbox Me.Job
 
I ask my lecturer today and he say this maby is microsoft access bug(because i can create in other new database , but not in my database), and he give me a tips that cab create more table to put more data validation then group the table together . Any idea about this?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom