Need Help - running total

L

learning_codes

Hi,

I use this code to run the query. It works fine the first time from 1
to 10. When i rerun the query, I got 11-20. Can you help me how to
stop rerun and I prefer to have 1 to 10 if I want to rerun. I still
get 11-20. Help much appreciated.

Public Oldg1g2 As String
Public OrderNum1 As Long

Function getordernumber(Group2 As String)

newgg2 = Group2
If Oldg1g2 = Newg1g2 Then
OrderNum1 = OrderNum1 + 1
Else
Oldg1g2 = Newg1g2
OlderNum1 = 1
End If
getordernumber = OrderNum1

End Function


Thanks...
 
D

Dale Fye

I'm not sure what this question has to do with a running total

You could do this a couple of ways. Personally, I would use a static
variable inside my function rather than a public one, and would add a Reset
option to the function.

Public Function GetOrderNumber(Optional Reset as boolean = false)

Static OrderNum as long

If Reset = True then OrderNum = 0
OrderNum = OrderNum + 1
GetOrderNumber = OrderNum

Endif

This allows you to reset the function value to 1 whenever you want. All you
have to do is pass it a True value, something like:

me.txtOrderNumber = GetOrderNumber(true)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top