Solved

Invalid Use of Null Using the DMax Function

Posted on 2006-10-25
3
323 Views
Last Modified: 2012-06-27
I'm having a problem with the following code.  It is running a query (qrygetNum) that uses a mid function to separate the number from a document name (XXX-001).  It then adds one to this number.  The problem I'm having is when the query comes up with no results it gives me an 'Invalid Use of Null' error.  When the query comes up with no result I want it to give a document number of '001'.  I put the in If IsNull statement, but it's in the wrong spot, or it's the wrong code all together.  

Everything else works fine.  If there is an existing doc number it adds one to it.  The remainder of the code adds the doc name (DocAcro) to the number.


Dim DocNum As Integer
Dim DocExt As String
Dim DocAcro As String

DocAcro = Me.GeoFirstLetter & Me.FuncIden & Me.TypeIden
DocNum = DMax("[qryGetNum]![Number] + 1", "[qryGetNum]")
  If IsNull(DocNum) Then
  DocExt = "001"
  ElseIf DocNum <= 9 Then
  DocExt = "0" & "0" & DocNum
  ElseIf DocNum <= 99 Then
  DocExt = "0" & DocNum
 
  End If
 
 
  If vbNo = MsgBox("Are you sure you want to create document number" & " " & DocAcro & "-" & DocExt & "?", _
  vbYesNo, "Creating Document Number") Then Exit Sub
  ' Places the value of DocAcro + DocExt in the DocumentNumber field.
  Me.DocumentNumber.Value = (DocAcro & "-" & DocExt)
0
Comment
Question by:gfortuna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 250 total points
ID: 17805339
OK couple of things.
Under what circumstances does it give the error?
If there are no records returned from that query?
Where there are Null entries?

Your subsequent code seems to be to format your returned number - which can be achieved more easily.
What about

DocAcro = Me.GeoFirstLetter & Me.FuncIden & Me.TypeIden
DocNum = Nz(DMax("[Number]", "[qryGetNum]", "[Number] Is Not Null"),0) + 1

DocExt = Format(DocNum, "000")
0
 

Author Comment

by:gfortuna
ID: 17805413
Thanks for your help.  Your code worked perfectly, no errors.  
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17805459
Welcome. :-)
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question