Solved

Invalid Use of Null Using the DMax Function

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

749 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