Results 1 to 5 of 5
  1. #1
    Alocin is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2020
    Posts
    15

    Smile Button in Access 2016 to add +1 to last/highest value in a field

    Hi and thank you in advance everyone!
    I want to add +1 to the highest value in a table field populated by a form control by clicking on a button in this form.




    My table called "Requests" has a field called "Request#". I want to add a button in the form called "Add Request" so that when it is clicked, it will add +1 to the highest number in the form control / table field. If there is a macro that can do this I would really love it. VBA is a bit not so easy for me.
    however, I am using a VBA code (please see below) that works very well but I have to double click on the form Control "Request#" in order to add 1 to the greatest value in the table
    field. I need to have a button that will do the same thing. Any help if so much appreciated.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,538
    Quote Originally Posted by Alocin View Post
    ..... I am using a VBA code (please see below) .....
    You seem to have forgotten to attach the code
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Alocin is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2020
    Posts
    15
    Hi Bob, thank you for your quick reply.

    Well, as mentioned I am barely a novice in VBA so I am always hopeful to find what I consider an easier way, macros. I have figured out a way to use a macro.
    For the audience in Access 2016 using SetValue the macro is DMax("[FieldName]","[QueryorTableName]")+1. However, in Access 2016 "SetValue" does not show up on the drop down selections, so you must click on "Show All Actions" on the menu bar to see "SetValue".

    Bob, now I wonder if you can help on the following issue. I have the same issue on a subsequent form control called "RequestSub#". The table "Requests" has two fields that are associated, "Request#" and "RequestSub#". As needed, I need to have a button that increases the "RequestSub#" by +1; however, it must increase based on the associated "Request#". Does this make sense?
    In other words based on the request# the associated requestsub# will increase by +1 as we have the entry.
    here is my example:
    Request# RequestSub#:
    365 0 <--initial start value is 0
    366 0
    365 1
    367 0
    365 2
    366 1
    etc.
    Any help is so much appreciated. Also, should I make this another post/question?

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,538
    Alocin

    1) It's not a good idea to name any Access object using spaces or special characters like "#". Only exception is the underscore "_"

    2) Like most Access users with some experience, I do not use macros as we prefer to use VBA code, so I would be unable to help with those. That said, there is a striking similarity between what you posted:
    DMax("[FieldName]","[QueryorTableName]")+1
    and the kind of code that we would use, which would be the DMax() function with some criteria. Something like:
    DMax("[FieldName]","[QueryorTableName]","[NameOfTableField] = " & Me.[NameOfFormControl])+1
    if the "
    NameOfTableField" was numeric type. Syntax would be slightly different it were text.

    I would be happy to attempt to find a solution using code if you could post a copy of your db with just a few dummy records to show the problem.
    Compact and Repair the db, then "Zip" it before posting.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Alocin is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2020
    Posts
    15
    Good morning everyone,
    thank you to all who tried to help me with this question. I eventually got a macro to work using "SetValue" and the "DMax("[Request_Number]","[Requests]")+1".
    Btw I am now posting a different question and looking hoping you fine intellectuals can help me solve.


    Again thank you all very much!
    Alocin

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

Similar Threads

  1. Replies: 20
    Last Post: 04-27-2020, 01:22 PM
  2. Replies: 3
    Last Post: 08-29-2019, 01:04 AM
  3. Replies: 3
    Last Post: 03-17-2017, 08:00 AM
  4. Replies: 2
    Last Post: 11-13-2016, 08:15 AM
  5. Access 2016 Help Button?
    By Charles Hobbs in forum Misc
    Replies: 2
    Last Post: 12-16-2015, 09:39 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