Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24

    Red face Primary key generated by Year+month+day+unique number of the day.

    Hey everybody!.
    Im new in this forum and I really hope some good guy could give me a hand with this task. Iīm new with access and with VBA, Iīve already biuld a database but my personal proyect requires that the information of the costumers is stored in the following way.


    Year+month+day+unique id of the current day.
    So every day I can start from 1. The final code must be something like 20160109-01.
    I thank any help you could give me, I donīt ask for you to do my work but Iīm kind of frustrated to this point , so If any of you at least could put me in the right direction with one link I will be eternally grateful.
    Tank you.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    Constructing custom unique IDs is a common topic. Search forum and Google.

    Here is one for starters
    https://www.accessforums.net/access/...ers-21361.html
    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.

  3. #3
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24
    I've tried using this code
    DateSerial(Year(Date()), Month(Date()), Day(Date())) & [Id_dia]
    Id_dia represents the unique number asigned to a specific costumer that day.
    When I use the form view and I instert a number in that spot I get this phrase
    #ŋNombre?
    Everything is in spanish..
    Is it cuz the variable?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    Why do you need DateSerial? All you are doing is building the current date which can be captured by simply Date().

    Is this expression in a textbox? Did you prefix with = sign?

    =Format(Date(), "yyyymmdd") & "-" & [Id_Dia]
    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
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24
    I've tried with the one you just post June7, it seems to work :3 tank you

  6. #6
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24

    Calculated value in a text box does appear. [Me.Id = Format(Fecha(), "YYYYMMDD") & "-" & Me.Id_dia]

    First of all thanks June7 for that line of code.

    I decided to start over the form but when writing again that piece of information it didnīt work.
    Here is the full code.

    Private Sub TxtId_AfterUpdate()
    Me.Id = Format(Fecha(), "YYYYMMDD") & "-" & Me.Id_dia
    Me.Caption = "Folio N°" & Me.Id
    End Sub

    The txtbox es called TxtId the field in the related table is called Id. Iīm able to fill all other fields but this one is not generated . Of course I have a txtbox requesting the "Id_dia". I used the wizard to make the form. The Id is the main key for. Iīm quite new at this, so anything I which you could help me Iīll be eternally grateful.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    "didn't work" means what - error message, wrong result, nothing happens?

    Caption is a field in table?
    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.

  8. #8
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24
    No wrong result, the error message is that I must fill that field but I understand thatīs because Is a key field. Then nothing happens with the field.

    Caption just changes the Name of the form after it has gain the Id. I could get rid of that I just thought I would be nice XD.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    I don't understand the error message as you state it. What is the EXACT error message? Why field type is ID?
    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.

  10. #10
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24
    Well I clicked the error message in the Help button it lead me to this https://msdn.microsoft.com/es-es/lib...ffice.15).aspx

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    Spanish web page doesn't help me.

    The error message popup should have a message on it. What is that message (in English please).

    Is the ID field a text type?
    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.

  12. #12
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24
    Well Something weird has happen I was copyng the tables and forms to another proyect so I could zip it and upload it here then just for curiosity I executed the form and it worked...
    The Id field is short text. The pop up error doesnīt have a number on it. In the page I just link there is an option in the upper right corner where you can change it to English.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Pardon me for jumping in but *why* does this field need to be a Primary Key (PK) field? Indexed field fine, but PK?

  14. #14
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24
    Is a personal proyect based on the needs of where I work. Im a Chemist by profesion but I used to study C++ and java in the past; thereīs already a program but It lacks certain things.

    By the way the it just worked on one time now even the copy started failing...

  15. #15
    Anacronos is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2016
    Posts
    24
    I've re thinking the question and I think the real reason for that field to be the pk is that every morning we start counting from the client one and so on; It will quickly get out of hand cuz we usually keep two types of database virtual and in paper.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Generating unique ID using year/month
    By Integrate in forum Macros
    Replies: 7
    Last Post: 08-30-2015, 10:25 AM
  2. Change number to Year, Month, Days
    By trident in forum Forms
    Replies: 10
    Last Post: 05-25-2015, 08:16 AM
  3. Replies: 11
    Last Post: 11-11-2014, 06:04 PM
  4. Get last ID of primary key automatically generated
    By California2013 in forum Access
    Replies: 1
    Last Post: 09-12-2013, 05:57 AM
  5. Week Number of Month not Year?
    By kwooten in forum Queries
    Replies: 6
    Last Post: 05-01-2013, 06:59 AM

Tags for this Thread

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