Invalid use of Null error in Private sub (1 Viewer)

Funkyaccess

Registered User.
Local time
Today, 07:30
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?
 

dcb

Normally Lost
Local time
Today, 16:30
Joined
Sep 15, 2009
Messages
529
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
 

Funkyaccess

Registered User.
Local time
Today, 07:30
Joined
Oct 8, 2009
Messages
69
thanks I'll change that but in this case the null seems to lie with DATA_FOR
 

Funkyaccess

Registered User.
Local time
Today, 07:30
Joined
Oct 8, 2009
Messages
69
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.
 

dcb

Normally Lost
Local time
Today, 16:30
Joined
Sep 15, 2009
Messages
529
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?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:30
Joined
Aug 30, 2003
Messages
36,129
Neither Integer nor Date can handle a Null. Try

Function validate_SO_record(database As Variant, data_for As Variant)...
 

dcb

Normally Lost
Local time
Today, 16:30
Joined
Sep 15, 2009
Messages
529
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
 

Funkyaccess

Registered User.
Local time
Today, 07:30
Joined
Oct 8, 2009
Messages
69
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.
 

Funkyaccess

Registered User.
Local time
Today, 07:30
Joined
Oct 8, 2009
Messages
69
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.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:30
Joined
Aug 30, 2003
Messages
36,129
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.
 

dcb

Normally Lost
Local time
Today, 16:30
Joined
Sep 15, 2009
Messages
529
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
 

Funkyaccess

Registered User.
Local time
Today, 07:30
Joined
Oct 8, 2009
Messages
69
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

Top Bottom