Setting a starting point for counter

I am utilising a counter that can be called from various points in a project.

The routine is in a module and evertime it is called the integer increments by one. However I need the counter to start from 99004500 therefore how do I set this as the initial integer value.
Who is Participating?
eab111098Connect With a Mentor Commented:
use a sub main() subroutine as your startup. goto project->properties and set your start up for the project to sub main(). then in a module, create a subroutine called "public sub main()". in the main() subroutine, set your counter to whatever value you desire and then do a form.load event on your startup form. this will initialize the counter to your desired value and load up the initial form you want.

You can define a Const with the value that you want

In the next code every time you click the Command Button you can see the secuencie
 99004501 , 99004502 , ...

Const INIT_VALUE = 99004500

Private Sub Command1_Click()
Dim result As Long
MsgBox INIT_VALUE + counter()
End Sub

Public Function counter() As Integer
Static aux As Integer

aux = aux + 1
counter = aux
End Function

Mister_SimonAuthor Commented:
Works Ed !!

although had to use a form.SHOW in the module rather than form.LOAD as that did not work.

Do you think this will cause any problems ????
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.