You are here:

Using MS Access/DMAX for sequential numbering by DAY

Advertisement


Question
Hi Scott,
Doing a variant of scenario 2 with re-starting sequential numbering each day.

Code is:
Me.txtOrd_Seq = Nz(DMax("[Ord_Seq]", "tblOrders", "Year([DateSubmitted]) = " & Year(Me.txtDateSubmitted) & " AND Month([txtDateSubmitted] & " AND Day([txtDateSubmitted]) _
= " & Day(Me.txtDateSubmitted)),0)+1

Getting syntax error.

Date is DateSubmitted from calendar control pick.
Display of number is no problem through concat & 2 fields:
Ord_Seq is integer type long.

Answer
OK, so you are looking to start a new sequence for each day and increment the sequence within the day.
So doesn't this work:

Me.txtOrd_Seq = Nz(DMax("[Ord_Seq]", "tblOrders", "[DateSubmitted] = #" & Me.txtDateSubmitted & "#"),0)+1

If DateSubmitted includes time as well as the date, then try this way:

Me.txtOrd_Seq = Nz(DMax("[Ord_Seq]", "tblOrders", "DateValue([DateSubmitted]) = #" & DateValue(Me.txtDateSubmitted) & "#"),0)+1

If you absolutely need to break it out you can try:

Me.txtOrd_Seq = Nz(DMax("[Ord_Seq]", "tblOrders", "Year([DateSubmitted]) = " & Year(Me.txtDateSubmitted) & " AND Month([txtDateSubmitted]) & Month(me.txtDateSubmitted) & " AND Day([txtDateSubmitted]) = " & Day(Me.txtDateSubmitted)),0)+1

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scottgem

Expertise

I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.

Experience

I've been designing databases for over 25 years working with dBase, FoxPro, Approach and Access.

Organizations
Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

Education/Credentials
Brooklyn College BA

©2016 About.com. All rights reserved.