dcsimg
Results 1 to 4 of 4

Thread: [RESOLVED] DMax invalid use of null

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    34

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,873

    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

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    Baby Steps a guided tour
    IsDigits() and IsNumber() functions Wichmann-Hill Random() function >> and << functions for VB CopyFileByChunk

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2010
    Posts
    34

    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
  •  



Featured


Click Here to Expand Forum to Full Width