Invalid use of Null error in Private sub

Funkyaccess

Registered User.
Local time
Today, 06:09
Joined
Oct 8, 2009
Messages
69
Hi,

I want to check my values before they update a record.

this is the private sub on the form
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'On Error GoTo err_validations
    Dim l_check As Boolean
    
    l_check = validate_SO_record(Me.database_id, Me.data_for)
    'If (l_che = False) Then GoTo err_validations
    
    
    Exit Sub
'err_validations:
    MsgBox gblErrorMsg, vbCritical, "Validation Error"
End Sub

ANd this is the validation function which is part of a standalone module
Code:
Function validate_SO_record(database As Integer, data_for As Date) _
As Boolean
    If (IsNull(database) = True) Then
        gblErrorMsg = "Please select a Database."
        validate_SO_record = False
        Exit Function
    ElseIf (IsNull(data_for) = True) Then
        gblErrorMsg = "Please select a Cashbook Date."
        validate_SO_record = False
        Exit Function
    End If
    validate_SO_record = True
    
End Function

How do I get around this error message?
 
Two thoughts
If me.databaseID = Null then it will not hand off to the function as a integer...
database is a reserved word and should not be used as a variable
 
thanks I'll change that but in this case the null seems to lie with DATA_FOR
 
dcd where about in SA are you from? I'm in the UK but born and raised in sunny Durb's. Should I declare the variable type in the function.
 
sme would apply
why not use the nz function?
l_check = validate_SO_record(Me.database_id, nz(Me.data_for,0)

Then pass to the function as a var?
 
Neither Integer nor Date can handle a Null. Try

Function validate_SO_record(database As Variant, data_for As Variant)...
 
dcd where about in SA are you from? I'm in the UK but born and raised in sunny Durb's. Should I declare the variable type in the function.
PE, but in JHB now
I would dec a variant type for both
 
Whats sme?
Sorry its been awhile since I've done vba coding. I've been using ORACLE PL/SQL for a while and just trying to remember syntax.
 
If I use variant can i test to ensure its a date or a valid database id?

dcb - cool you must be glad that summers coming up. Winter is Shyt here but the summers are really good. I have some family that stay in boxsburg actually they around the corner from east rand mall and some family in krugersdorp.
 
Variant is the only data type that can take a Null. You can still test to see if it's a date or valid database id as you already are.
 
Just a thought - can I ask why you are using a function here?
Seems like you are making it overly complicated unless you are using this function in multiple places
 
I want to run this function on a form when a user updates a record as well as when they input. So I thought if I make it a function in a module I can call it from my form and I may need it somewhere else.
 

Users who are viewing this thread

Back
Top Bottom