Results 1 to 4 of 4
  1. #1
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117

    Using VBA to autogenertae a Unique ID

    Hello everybody,

    I have posted before but my after talking to my manager we have come up with a format with a unique id that he wants me to auto generate. I have a form with three fields, which are
    1.model (name is "model_type")
    2.date
    3.Id(primary key)
    The model is a combo box with options the user chooses. Then I have the date which is automatically put in with the function "Date()" in default value. Then I have an Id field with an auto generate button I have created right next to the field. First question is, should the id field be auto number or text data type? Second question is how do I code the button to first of all to link to the field so when I click on it, it will auto generate the id( the id field name is "uniqueid"), and third, how do I code the button to auto generate the unique id. The format of the id my boss has given me is first the model, depending on what the user clicks on from the combo box, second is the current year, it can be 2016 or just 16, and then 001 or 0001, either is fine. Then after that, the last part of the id 001 will increment to 002 or 0002 to 003 or 0003 and so on after clicking the button. So for example the format of the id that can be auto generated could be "S72-16-001" or "S89-2016-0001", the first part depending on what model the user picked l and the second id generated in the database can be "S72-16-002". All help will be appreciated. I am a beginner in access and have very little knowledge on vba.

    Thanks!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you dont need vb. This can be done in a query

    homekey: [model] & "-" & date() & "-" & [ID]

  3. #3
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    duplicate post in this forum

  4. #4
    banpreet is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    117
    Hey ranman256, how does this work sorry I am new. I still want this linked to a click of a button, but if the way you say to do it through a query will autogenerate the without clicking the button, that will be fine. But will this way auto generate the id for the user on the form, without any of us going to the table or query to put in the id? Can you please explain where I would type this and do this, sorry im a noob.

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

Similar Threads

  1. Using VBA to autogenertae a Unique ID
    By banpreet in forum Programming
    Replies: 8
    Last Post: 07-13-2016, 08:25 AM
  2. Replies: 22
    Last Post: 03-03-2013, 02:00 PM
  3. Unique queries - Unique Count
    By bigfish in forum Queries
    Replies: 7
    Last Post: 03-14-2012, 01:28 PM
  4. More unique valuecombinations
    By superfury in forum Access
    Replies: 3
    Last Post: 08-19-2011, 06:08 AM
  5. how to set a unique ID
    By archie in forum Access
    Replies: 1
    Last Post: 09-08-2009, 04:28 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