Results 1 to 9 of 9
  1. #1
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136

    Adding one digit to new record in form


    Hi all,
    I have a table where the Record_ID is the key field. I want to program that field in my form to add one digit to the highest record ID in the table every time a new record is added. Currently my Add Record button has the code below. How do I code this?


    Private Sub cmd_add_record_Click()
    Me.AllowAdditions = True
    DoCmd.GoToRecord , , acNewRec
    End Sub

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Use an AutoNumber or DMax()
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136
    Quote Originally Posted by moke123 View Post
    Use an AutoNumber or DMax()
    Can you please help me with the syntax?

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Autonumber is a datatype in your table. It auto increments a number.

    the syntax for dmax is- DMax ( expression, domain, [criteria] )

    https://www.techonthenet.com/access/...omain/dmax.php
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Quote Originally Posted by matey56 View Post
    Can you please help me with the syntax?
    My first point of call is Google?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136
    Quote Originally Posted by moke123 View Post
    Autonumber is a datatype in your table. It auto increments a number.

    the syntax for dmax is- DMax ( expression, domain, [criteria] )

    https://www.techonthenet.com/access/...omain/dmax.php
    Unfortunately the table is in SQL Server and not Access.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Quote Originally Posted by matey56 View Post
    Unfortunately the table is in SQL Server and not Access.
    Never used it from Access, but if the tables are linked to the be sql server, why would it not work?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    136
    Quote Originally Posted by Welshgasman View Post
    Never used it from Access, but if the tables are linked to the be sql server, why would it not work?
    I'm not saying it won't work. I'm just hopeless when it comes to VB script. If the field name is Auto_Increment and the table is Table1, what is the code I need to enter on the click event to have it add 1 digit to each new record?

  9. #9
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 1
    Last Post: 11-19-2018, 07:57 PM
  2. Replies: 6
    Last Post: 05-09-2017, 09:13 AM
  3. Replies: 4
    Last Post: 08-14-2012, 07:14 AM
  4. Update the data to be in certain digit form
    By Nouri31 in forum Access
    Replies: 1
    Last Post: 01-17-2012, 01:34 PM
  5. Adding a 0 to single digit imports
    By TheWolfster in forum Access
    Replies: 6
    Last Post: 02-16-2010, 05:19 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