Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Usage of DMAX statement
John Miller 
       
2 years ago
Hello all, I am still trying to get DMAX to work to give me the last "OrderDate" of a customer, it just gives me thew current date 10/1/2024, even clients that I know have not had an order for at least 3 years. I have a simple form based on the client query and a text box to show the last order date. here is the value in the Control source of the text box: =DMax("OrderDate","OrderProcessing","CustomerID=" & [CustomerID]). Can someone tell me what I am doing wrong?
Adam Schwanz  @Reply  
           
2 years ago
Looks right, is customerID the right field/correct name on the form?

Is this form creating a new order when you open it? (and thus automatically making the most current order be today)

Try hardcoding it with a different customer, like CustomerID=1 or something and see what you get.
John Campbell  @Reply  
     
2 years ago
I know this is a dumb question, but is your orderdate field a date/time data type?  What you have should be working and also make sure that your OrderDate field does not have a default date in the table..
Kevin Yip  @Reply  
     
2 years ago
Note that [CustomerID], as used in your code, is the value from the currently selected record on your form.  Depending on how your form is set up, such as in a continuous form, the currently selected record may not give you the right value.  Since your form is based on a query as you said, consider using DMax inside the query, name the field [LastOrderDate], then use =[LastOrderDate] as the control source of your form field.
John Miller OP  @Reply  
       
2 years ago
Thank you for your responses To answer Adam's question the form does not create a new record, display only, the field customerid is the correct one. tried hardcoding customerid of one I know does not have a record on 10/1/2024 no date shown. John's question, the orderdate field is a date/time field. Kevin's question The [customerid] is the customerID on the form, changed form to continous. Still get either no date or 10/1/2024, this date if from the table I am using last record on it 10/1/2024.
Alex Hedley  @Reply  
           
2 years ago
What if you do, in a query
SELECT TOP 1 OrderDate
FROM OrderProcessing
WHERE CustomerId = 1
ORDER BY OrderDate DESC;
Kevin Yip  @Reply  
     
2 years ago
The only ways you get 10/1/24 or no date is when DMax's criteria is always true or always false.  For instance:

     DMax("OrderDate", "OrderProcessing", True)

will always give you the max date of the whole table, which is 10/1/24 in your case.  And:

     DMax("OrderDate", "OrderProcessing", False)

will always return Null (the blank date that you see).

I can't think of a scenario why you are seeing this.  But the above is how you will get what you are seeing.  So something is fishy with your criteria in DMax.  Look into it.
John Miller OP  @Reply  
       
2 years ago
Thank you for your response I will Try them  and let you know outcome. Tomorrow.
John Miller OP  @Reply  
       
2 years ago
hello all just wanted to let you know that I finally got Died to do what  wanted it t do. Seems it was all on me miss used field names I felt really bad about the whole thing. All is good now. Again thank you all for your assistance.
JohnM

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 8/8/2026 1:40:10 AM. PLT: 1s