Help w/ static variable in a query

G

Guest

I'm having a little trouble with the function below. When use it in a query,
the query only accesses the function once and returns the one value for all
of records. How do I get it to call the function for each record and return
a counter? BTW, I reset the static variable before I call the function.

Thanks,
Chris

Public Function OrderLineCounterA()

Static lngLineCounterA As Long

If lngLineCounterA < lngCounterStart Then lngLineCounterA =
lngCounterStart

lngLineCounterA = lngLineCounterA + 1

OrderLineCounterA = lngLineCounterA

End Function
 
G

Guest

Well, its the first time I noticed that.
The function will run only once in the query incase you are not passing any
value to it.

Passing a parameter to the function of one of the fields in the query will
run the function every record, even if you are not using it in the function

Public Function OrderLineCounterA(MyParam As Variant)

Static lngLineCounterA As Long

If lngLineCounterA < lngCounterStart Then lngLineCounterA =
lngCounterStart

lngLineCounterA = lngLineCounterA + 1

OrderLineCounterA = lngLineCounterA

End Function
====================
In the query:
Select TableName.* , OrderLineCounterA([SomeFieldName]) As Something From
TableName
 

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