Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Help with DCount
Gary 

14 years ago
Need a little help here, I am trying to create a custom counter for a database I am creating. Basically the customer wants a serial number for each record formatted by year then sequentially from 101 and so on. IE 12-101, 12-102 and resets each year IE 13-101, 13-102.

So I created this formula

CurYear = Format(Now(), "yy")
CurCount = DCount("[ID]", "Master", "left([sample_number],2)=CurYear")

If CurCount < 1 Then
   x = CurCount + 101
   SAMPLE_NUMBER = CurYear & "-" & x

ElseIf CurCount = 1 Then
   x = CurCount + 101
   SAMPLE_NUMBER = CurYear & "-" & x

Else
   x = CurCount + 101
   SAMPLE_NUMBER = CurYear & "-" & x
End If

The problem I am having is dcount is ignoring the variable CurYear and just counts all the records.

DCount("[ID]", "Master", "left([sample_number],2)=CurYear")

is there a way to use Curyear as a variable in that position or do I have to approach this from a different way?

So long story short I was trying to count only the records that matched the current year and add 101 to it. then Concatenate them to the formula 12-100 + etc

Any suggestions would be great help.

Gary


Reply from Richard Rost:

Try this:

CurCount = DCount("[ID]", "Master", "left([sample_number],2)='" & CurYear & "'")

Access will convert it to:

CurCount = DCount("[ID]", "Master", "left([sample_number],2)='12'")

We talked about this in the first DLOOKUP class, I think. Also, you do realize that your numbering scheme is going to run into problems in the year 2100. Just sayin'. :)

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: 5/17/2026 4:24:13 AM. PLT: 1s