Solved

Invalid Use of Null Using the DMax Function

Posted on 2006-10-25
3
311 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
  • 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

810 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