How to validate three condition, before providing Error Msg (1 Viewer)

kimpida

Registered User.
Local time
Today, 14:17
Joined
Feb 11, 2014
Messages
15
:banghead:I am trying to write following code, I want Msg to pop, when all three condition are true, but it not working, any help will be appriciated


'''Non Budgeted Projects need Explanation and Variance class"

If Me.ID.Value >= 90000 And and Me.Variance_Class = "" and Me.Comments_Explanation_Delta_____100K = "" Then

MsgBox "This project is Unbudgeted. Please Add 'Variance Class' and provide Explanation why this project is Unbudgeted project has been added.", vbExclamation, "Rules Checker..."
CheckRules = False
GoTo Exit_CheckRules
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:17
Joined
Aug 30, 2003
Messages
36,125
I moved your thread from the introductions forum. In case your fields are Null rather than "", try this test for each:

Nz(Me.Variance_Class, "") = ""
 

kimpida

Registered User.
Local time
Today, 14:17
Joined
Feb 11, 2014
Messages
15
thanks it is working, but now I have an other question.

If (Me.Variance_From_Budget < 99999 And Me.Variance_From_Budget <= -99999) And (Me.Variance_Class = "" Or IsNull(Me.Variance_Class)) Then
MsgBox "This project is onbudget project, please add Variance Class 'Onbudget' .", vbExclamation, "Rules Checker ...."
CheckRules = False
GoTo Exit_CheckRules
End If

My variance from Budget is -200,000, I am still getting the msg, since it is less 100,000.
what I need is a msg, when variance from Budget is 100,000 or -100,000.

Does vba has between operator, like Sql has.

:banghead:
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:17
Joined
Aug 30, 2003
Messages
36,125
You're getting the message because it's less than -99999. ;)
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 17:17
Joined
Oct 17, 2012
Messages
3,276
In addition,

Code:
If (Me.Variance_From_Budget < 99999 And Me.Variance_From_Budget <= -99999)

is suspect, because if Me.Variance_From_Budget <= -99999, then it will ALWAYS be < 99999. I think you meant for the second one to be '>='. That should work.

As long as you're not submitting a value of -200,000. ;)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:17
Joined
Aug 30, 2003
Messages
36,125
I guess my hint wasn't good enough?
 

kimpida

Registered User.
Local time
Today, 14:17
Joined
Feb 11, 2014
Messages
15
Thanks for all your help

One more problem

How to find, the null value in the code?

I am getting following error in my code:

"Invalid use of Null"
 

pr2-eugin

Super Moderator
Local time
Today, 22:17
Joined
Nov 30, 2011
Messages
8,494
Could you show the code (that you are using) which is causing the error?
 

kimpida

Registered User.
Local time
Today, 14:17
Joined
Feb 11, 2014
Messages
15
Code:
'''Non Budgeted Projects need and Variance class
If Me.ID.Value >= 90000 And (IsNull(Me.Variance_Class) Or Me.Variance_Class = "") Then
MsgBox "This project is Unbudgeted. Please Add 'Variance Class' and provide Explanation why this project is Unbudgeted project has been added.", vbExclamation, "Rules Checker..."
'Me.Annual_Summarized_Budget.Locked = True
CheckRules = False
GoTo Exit_CheckRules
End If
'''Non Budgeted Projects need Explanation
If Me.Variance_Class = "Unbudgeted" And (IsNull(Me.Comments_Explanation_Delta_____100K) Or Me.Comments_Explanation_Delta_____100K = "") Then
MsgBox " This is a non budgeted project, please provide an explanation, why this project has been added.", vbExclamation, "Rules Checker..."
'Me.Annual_Summarized_Budget.Locked = True
CheckRules = False
GoTo Exit_CheckRules
End If
 
'''Non Budgeted Projects need Variance class to be Unbudgeted
If Me.ID.Value >= 90000 And Me.Variance_Class <> "Unbudgeted" Then MsgBox "This is a non budgeted project Please change variance class to unbudgeted.", vbExclamation, "Rules Checker..."
'Me.Annual_Summarized_Budget.Locked = True
CheckRules = False
GoTo Exit_CheckRules
End If

this my code and I don't know, where Null is coming from. I am new to Access vba and inhertied this database with any documnetation.

thanks
:banghead:
 
Last edited:

pr2-eugin

Super Moderator
Local time
Today, 22:17
Joined
Nov 30, 2011
Messages
8,494
this my code and I don't know, where Null is coming from. I am new to Access vba and inhertied this database with any documnetation.
You would exactly know where this Null is coming from. Have you left Variance_Class or Comments_Explanation_Delta_____100K - Null? Does not matter if the ID is >= 90000. If they are Null you will hit a brick wall somewhere, you need to analyze your logic correctly.
 

kimpida

Registered User.
Local time
Today, 14:17
Joined
Feb 11, 2014
Messages
15
Code:
'''Non Budgeted Projects need and Variance class
If Me.ID.Value >= 90000 And (IsNull(Me.Variance_Class) Or Me.Variance_Class = "") Then
MsgBox "This project is Unbudgeted. Please Add 'Variance Class' and provide Explanation why this project is Unbudgeted project has been added.", vbExclamation, "Rules Checker..."
'Me.Annual_Summarized_Budget.Locked = True
CheckRules = False
GoTo Exit_CheckRules
End If
'''Non Budgeted Projects need Explanation
If Me.Variance_Class = "Unbudgeted" And (IsNull(Me.Comments_Explanation_Delta_____100K) Or Me.Comments_Explanation_Delta_____100K = "") Then
MsgBox " This is a non budgeted project, please provide an explanation, why this project has been added.", vbExclamation, "Rules Checker..."
'Me.Annual_Summarized_Budget.Locked = True
CheckRules = False
GoTo Exit_CheckRules
End If

'''Non Budgeted Projects need Variance class to be Unbudgeted
If Me.ID.Value >= 90000 And Me.Variance_Class <> "Unbudgeted" Then 
 
MsgBox "This is a non budgeted project Please change variance class to unbudgeted.", vbExclamation, "Rules Checker..."
'Me.Annual_Summarized_Budget.Locked = True
CheckRules = False
GoTo Exit_CheckRules
End If
[\CODE]

this my code and I don't know, where Null is coming from. I am new to Access vba and inhertied this database with any documnetation.

thanks
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 17:17
Joined
Oct 17, 2012
Messages
3,276
This is how your code should be presented here:

Code:
Public Function TempFunction()
 
    '''Non Budgeted Projects need and Variance class
    If Me.ID.Value >= 90000 And (IsNull(Me.Variance_Class) Or Me.Variance_Class = "") Then
        MsgBox "This project is Unbudgeted. Please Add 'Variance Class' and provide Explanation why this project is Unbudgeted project has been added.", vbExclamation, "Rules Checker..."
        'Me.Annual_Summarized_Budget.Locked = True
        CheckRules = False
        GoTo Exit_CheckRules
    End If
 
    '''Non Budgeted Projects need Explanation
    If Me.Variance_Class = "Unbudgeted" And (IsNull(Me.Comments_Explanation_Delta_____100K) Or Me.Comments_Explanation_Delta_____100K = "") Then
        MsgBox " This is a non budgeted project, please provide an explanation, why this project has been added.", vbExclamation, "Rules Checker..."
        'Me.Annual_Summarized_Budget.Locked = True
        CheckRules = False
        GoTo Exit_CheckRules
    End If
 
    '''Non Budgeted Projects need Variance class to be Unbudgeted
    If Me.ID.Value >= 90000 And Me.Variance_Class <> "Unbudgeted" Then
        MsgBox "This is a non budgeted project Please change variance class to unbudgeted.", vbExclamation, "Rules Checker..."
        'Me.Annual_Summarized_Budget.Locked = True
        CheckRules = False
        GoTo Exit_CheckRules
    End If
 
End Function

Also, don't forget the Ten Commandments of Access. In this case:

Thou shalt not use "SendKeys", "Smart Codes" or "GoTo" (unless the GoTo be part of an OnError process) for these will lead you from the path of righteousness.
 

kimpida

Registered User.
Local time
Today, 14:17
Joined
Feb 11, 2014
Messages
15
Sorry about it. My new at it. Please be paitent with me.

thanks
 

Users who are viewing this thread

Top Bottom