Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get an increment dinamically for/in a query?

getting an incremental value

How to get an increment dinamically for/in a query?

by  Cagliostro  Posted    (Edited  )
Create in a VBA module such code:
[color blue]
global IncrementVariable as integer
function IncrementValues() as integer
IncrementVariable = IncrementVariable + 1
IncrementValues = IncrementVariable
end function
[/color]
in the query you will do
[color blue]
select IncrementValues(), xxx, yyy, zzz from yourTable
[/color]
Each time you want to use a new counter, to reser the increment, or when you use it first time I recommend to run the code:
[color blue]
IncrementVariable = 0
[/color]
or make a function
[color blue]function ResetCounter()
IncrementVariable = 0
end function[/color]
and call
[color blue]ResetCounter()[/color]
the last reseting method is more reliable.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top