Invalid use of Null (1 Viewer)

BennyLinton

Registered User.
Local time
Today, 10:07
Joined
Feb 21, 2014
Messages
263
I have an Access database that is logging changes to a specific field on a form. The code is working great unless the user clears the field... then I get 'Invalid Use of Null' even though the field in my SQL Server backend can accept nulls. Any ideas?:

Function LogChanges(lngID As Long, Optional strField As String = "")
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim varOld As Variant
Dim varNew As Variant
Dim strFormName As String
Dim strControlName As String

varOld = Screen.ActiveControl.OldValue
varNew = Screen.ActiveControl.value
strFormName = Screen.ActiveForm.Name
strControlName = Screen.ActiveControl.Name
Set dbs = CurrentDb()
Set rst = dbs.TableDefs("ztblDataChanges").OpenRecordset

With rst
.AddNew
!FormName = strFormName
!ControlName = strControlName
If strField = "" Then
!FieldName = strControlName
Else
!FieldName = strField
End If
!recordid = lngID
!userName = Environ("username")
If Not IsNull(varOld) Then
!OldValue = CStr(varOld)
End If
!NewValue = CStr(varNew)
.Update
End With
'clean up
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
End Function
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 13:07
Joined
Apr 27, 2015
Messages
6,341
Try wrapping the variable in the Null function: Nz()
 

BennyLinton

Registered User.
Local time
Today, 10:07
Joined
Feb 21, 2014
Messages
263
I tried this: !NewValue = !NewValue = Nz(CStr(varNew), "") but get the same error
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 13:07
Joined
Apr 27, 2015
Messages
6,341
Sorry, I'm out of ideas. Good thing this site is crawling with folks a lot smarter than me who have been patiently waiting for me to pass this on!

Stand by, the Calvery is coming...
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 13:07
Joined
Apr 27, 2015
Messages
6,341
Prego! It is no problem at all. Is it possible to post a sanitized version of your DB? I would like to fiddle around because now I am curious...
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:07
Joined
Aug 30, 2003
Messages
36,126
Yes, though I don't know if either is necessary. This might work:

!NewValue = varOld
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 13:07
Joined
Apr 27, 2015
Messages
6,341
Barfing On the Null...

Funny, I can't find that term in ANY of my Access files.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:07
Joined
Aug 30, 2003
Messages
36,126
You probably have a newer version. They took it out because it was too technical for some people. :p
 

Users who are viewing this thread

Top Bottom