[RESOLVED] DMax invalid use of null
I am getting an error of Run-time error '94': invalid use of Null. I have the code below. This is when I am creating a new record and there isn't data to add to... I have a default value of 0 in the docSeries column. Any ideas???
Code:
Option Explicit
Public Function getDocID(TypeID As Integer, series As Single, version As Single) As Long
Dim strWhere As String
strWhere = "DocType = " & TypeID & " AND DocSeries = " & series & " AND DocVersion = " & version
getDocID = Nz(DLookup("DocID", "tblDocInfo", strWhere))
End Function
Public Function getSeries(docID As Long) As Single
On Error GoTo errlabel
Const fldName = "DocSeries"
Const tblName = "tblDocInfo"
getSeries = DLookup(fldName, tblName, "DocID = " & docID)
Exit Function
errlabel:
MsgBox Err.Number & " " & Err.Description
End Function
Public Function getNextSeries(docID As Long) As Single
getNextSeries = getSeries(docID) + 0.001
End Function
Public Function getMaxSeriesForType(TypeID As Integer) As Single
Const fldName = "DocSeries"
Const tblName = "tblDocInfo"
Const typeName = "DocType"
Dim strWhere As String
strWhere = typeName & " = " & TypeID
getMaxSeriesForType = DMax(fldName, tblName, strWhere)
End Function
Public Function getNextSeriesForType(TypeID As Integer) As Single
getNextSeriesForType = getMaxSeriesForType(TypeID) + 0.001
End Function
Re: DMax invalid use of null
as you don't specify which line gives the error, hard to be precise
try adding a nullstring to the field that may contain a null
Re: DMax invalid use of null
If no record exists, DLookup() and DMax() will return a Null value.
You cannot assign a Null value to a Long or a Single variable.
Change 0 to whatever default value you want.
Code:
getDocID = Nz(DLookup("DocID", "tblDocInfo", strWhere), 0) '-- Long
getSeries = Nz(DLookup(fldName, tblName, "DocID = " & docID), 0) '-- Single
getMaxSeriesForType = Nz(DMax(fldName, tblName, strWhere), 0) '-- Single
Re: DMax invalid use of null
anhn: great solution!! worked perfectly. Thank you SO much!