Results 1 to 9 of 9
  1. #1
    Buns1976 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    16

    Generate number increments by date in form

    Hi Y'all,



    We generate several invoices for products weekly. In my filtered form. In my code below I'm trying to get my invoice field to generate consecutive invoice numbers based on the first date
    in the first record "BY DATE". In other words in the InvoiceNumber field in the first record we type 20191501 then the next record would return 20191502, etc. on the date of 2/15/19.
    Then on the next date of 2/16/19, we would start over with 20191601, 20191602 etc. Everything in the code works until we change to the next date and can't see to get it correct? Very new to all of this
    so some simple help would be appreciated.

    Thanks,



    Code:
    Dim ID As LongID = DMax("ProductID", "ProductT")
    DoCmd.GoToRecord , , acNewRec
    ProductName = DLookup("ProductName", "ProductT", "ProductID=" & ID)
    SalePrice = DLookup("SalePrice", "ProductT", "ProductID=" & ID)
    DateEntered = DLookup("DateEntered", "ProductT", "ProductID=" & ID)
    InvoiceNumber.SetFocus
    If Me.NewRecord = True Then
            Me.Slot = Nz(DMax("InvoiceNumber", "ProductT"), 1) + 1
        End If

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    I'm smelling a few different problems here...

    But first, where are getting the date from? Is [By Date] a field name in the ProductT table? Should the date not just be the current date? What is the data type of the invoice number field?

  3. #3
    Buns1976 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    16
    On the date yes its a field in the table. Todays date would probably work just the same. Data type is number!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    What you show is a structure of yyyyddXX. That doesn't really make sense. Every month has a day 15.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Buns1976 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    16
    June7 what exactly are you referring to? What doesn't make sense?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Quote Originally Posted by Buns1976 View Post
    in the first record we type 20191501 then the next record would return 20191502, etc. on the date of 2/15/19.
    Then on the next date of 2/16/19, we would start over with 20191601, 20191602 etc.
    2019 15 01 = year 2019, day 15, sequence 01
    2019 15 02 = year 2019, day 15, sequence 02
    2019 16 01 = year 2019, day 16, sequence 01
    2019 16 02 = year 2019, day 16, sequence 02

    I presume you already went through that sequence in January. So what would you expect to happen in following months?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Buns1976 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    16
    June7 I understand what you're saying. Do you have a solution? The numbers are just numbers that we have used in the past in another program. I'm not opposed to something that would make sense.
    As I mentioned in my first post, I'm very new to this application so trying to learn.

    Thanks.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Generating custom unique identifier is a common topic. Review https://www.accessforums.net/showthread.php?t=23329
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    Apr 2017
    Posts
    1,679
    I use an ID like this in our ID device registry.

    The PK for table tblDevices is DeviceID, which has format "CCYYYYMMDD000", where "CC" is device group and subgroup, "YYYYMMDD" is device registering date (the format for date part is selected to allow to order devices by age), and "000" is the number for device of this type on registering day, preceeded with "0"'s.

    The form fDevices is source for subform sfDevices of fMain, where the user selects device type. Device group links main form and subform.

    On fDevices are control txtRegDate (It has "Date()" as default value, and I included it into table instead having an unbound control for it - to make script easier.), and a button comRegisterDevice.

    The Current event of fDevices sets visibility/enabled for controls on form, following rules:
    1. txtRegDate is enabled, when txtDeviceID Is Null (it is a new record), and disabled otherwise;
    2. comRegisterDevice is visible, when i txtDeviceID Is Null, and txtRegDate has some value (you need a Change event for txtRegDate to control this), and not visible otherwise;
    3. All other controls are disabled, when txtDeviceID is Null, otherwise enabled/disabled on usual conditions.

    BeforeUpdate event of fDevices controls, is the device registered whenever an attempt to move to another record is made. Whenever it finds txtDeviceID is Null, updating of record is canceled.

    On form are 2 unbound always not visible controls, txtCalcDeviceID1 and txtCalcDeviceid2, with source as:
    Code:
    txtCalcDeviceID1=[txtParentDevGroup] & Format([txtRegDate],"yyyymmdd")
    txtCalcDeviceID2=CInt(Nz(Right(DMax("DeviceID","tblDevices","LEFT(DeviceID,10)='" & [txtCalcDeviceID1] & "'"),3),0))
    The OnClick event of button comRegisterDevice calculates DeviceID value for new record, writes it into txtDeviceID, saves the record, and resets visible/enabled properties for all controls in form. The new DeviceID is calculated as:
    Code:
    Private Sub comRegisterDevice_Click()
        Me.txtDeviceID = Me.txtCalcDeviceID1 & Format((Me.txtCalcDeviceID2 + 1), "000")
       ...

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

Similar Threads

  1. Replies: 2
    Last Post: 08-04-2017, 12:37 PM
  2. Replies: 5
    Last Post: 05-10-2014, 01:14 PM
  3. How to generate a number in a form
    By Tuckerbox2081 in forum Access
    Replies: 2
    Last Post: 01-08-2014, 08:44 AM
  4. Replies: 3
    Last Post: 12-07-2013, 01:12 AM
  5. Replies: 9
    Last Post: 06-20-2011, 03:42 PM

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