Results 1 to 2 of 2
  1. #1
    DatabaseIntern is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    20

    Using Date and Occurence count to create a name

    Okay, So I am fairly familiar with access, but I having an issue that I think should be fairly simple to figure out.



    I am cataloging MOC (management of change) forms from 3 different power plants, I would like the name to automatically create itself as the intials of the plant, followed by the date created, and heres the kicker, followed by the sequential number of which MOC this is (like how many have been done this year) formatted with 4 digits.

    Example, it is the second MOC form the year 2013 at plant "A" - todays date is 7/11/2013

    I want to be able to automatically fill out the name as:

    A-201307110002 ( that is Plant A, year 2013, month 07, day 11, MOC# 0002 AT PLANT A) I am having no trouble with the date, or really even the plant part, but I cannot figure out how to get that last number in there. Any help would be appreciatted, I will also answer all questions as I am sure this is confusing.

    Thanks in advance!

    BTW my DB is a very simple one dimension list of MOC number, sponsor, etc...

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    let's assume:
    your form name is TESTFORM
    your plant name field is called PLANT
    the table storing your information is called TblTest
    The field storing your label in is called MOC

    the code to create your number would be something like

    Code:
    Dim sMOC
    Dim sMaxMOC
    
    sMOC = Plant & "-" & DatePart("yyyy", Date)
    
    sMaxMOC = DLookup("Max([MOC])", "tblTest", "left([MOC], 6) = '" & sMOC & "'")
    If IsNull(sMaxMOC) Then
        sMOC = sMOC & Right("0" & DatePart("m", Date), 2) & Right("0" & DatePart("m", Date), 2) & "0001"
    Else
        sMOC = sMOC & Right("0" & DatePart("m", Date), 2) & Right("0" & DatePart("m", Date), 2) & Right("0000" & CInt(Right(sMaxMOC, 4)) + 1, 4)
    End If
    
    MOC = sMOC
    you'd have to run this whenever you changed the plant

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-15-2013, 03:16 AM
  2. Replies: 6
    Last Post: 02-13-2013, 04:54 AM
  3. Report that inludes non-occurence?
    By chellelynn77 in forum Reports
    Replies: 3
    Last Post: 12-19-2011, 03:09 PM
  4. How to track/count the occurence of a particular field
    By jessica.ann.meade in forum Reports
    Replies: 4
    Last Post: 02-09-2011, 01:41 PM
  5. First and second occurence
    By jamphan in forum Queries
    Replies: 6
    Last Post: 08-23-2010, 09:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums