Vba example updating a text box

You will notice that by default the lowest value we can reach is 0, with the highest value being 100.

If you have not guessed already, this can be easily changed in the Properties window for the Spin Button under the Max and Min Properties.

You will notice that the date in the Text Box will increment by one day each time.

Using this method you can ensure that the User will not type an invalid date that is not recognized by Excel or miscalculate the date from the number of days chosen. One Control that Excel has which is not shown by default is the Calendar Control.

This simply tells our Spin Button what value to increment by.

The default is 1, but we can change this to any value that fits within the scope of a Long, ie; -2, 147, 483, 648 to 2, 147, 483, 647.

We could simply allow the user to type in a number and/or use the Spin Button Control to increment up to the desired number.In previous lessons we looked at the fact that the user may mistype their information so we need to include as much validation checking as we possibly can.Obviously if the user will be typing their name there is no validation check that we can really do unless of course we have a list of all possible names that would be entered into it in which case we would end up using a Combo Box to store these names.Once we have done this we can assume as safely as possible that the number chosen by the user using the Spin Button will meet any given criteria that we have determined.Let us now assume we have a scenario where we have a Text Box always defaulting to today's date and we want the user to be able to increment that date by one day up to any day one year ahead.

Leave a Reply