|
-
Apr 14th, 2010, 01:03 PM
#1
Thread Starter
Member
[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
-
Apr 15th, 2010, 05:56 AM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 15th, 2010, 06:45 AM
#3
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
-
Apr 15th, 2010, 01:26 PM
#4
Thread Starter
Member
Re: DMax invalid use of null
anhn: great solution!! worked perfectly. Thank you SO much!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|