Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Invalid Use of Null Using the DMax Function

Posted on 2006-10-25
3
Medium Priority
?
334 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 1000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

916 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