How To Have MS Access Increment A Number Without An Autonumber VBA

So I had an interesting question come my way today via the chatbox on this website.

Basically it was to increment a value in a label based on the button that was clicked. Here is what part of the form looked like:

The data was saved and read from this table:

So if the green “+10” button was clicked, 10 got added to the value of the table and was displayed in the form’s label.

The similar functionality happened when you clicked on the orange, blue, and purple buttons.

Here is the code used when you click the corresponding buttons (you can add or subtract from lngCounter to fit the button)

What the code does is lookup the value in the table and assigns it to a variable, lngCounter, then the quantity of the button clicked on it totaled with it, and then the new value gets updated in the table.

To make sure only one row gets updated, we use the “WHERE ID=x”.

Then the new value gets reflected in the caption property of the label on the form.

Thanks for a fun question.

Free! Subscribe To Our YouTube Channel!

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather


Call Erik Now