Solved

Invalid Use of Null Using the DMax Function

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now