How to create a function

C

Crystal Sharp

I copied this function's code from a MSDN sample and it worked in report. But
it does not work when I use it in query. Can someone help me modify it?
Thanks in advance.

The purpose of the function is to mark a record that is out of sequence with
*: 1, 2, *4, 5, *7

Dim GlobalFlag As Variant


Public Function SetFlag(x As Variant)
If GlobalFlag <> x - 1 Then
SetFlag = "*"
Else
SetFlag = " "
End If

GlobalFlag = x



End Function
 
F

fredg

I copied this function's code from a MSDN sample and it worked in report. But
it does not work when I use it in query. Can someone help me modify it?
Thanks in advance.

The purpose of the function is to mark a record that is out of sequence with
*: 1, 2, *4, 5, *7

Dim GlobalFlag As Variant

Public Function SetFlag(x As Variant)
If GlobalFlag <> x - 1 Then
SetFlag = "*"
Else
SetFlag = " "
End If

GlobalFlag = x


End Function

Copy and paste that code (including the DIM Global as Variant) into a
Module.
Then call it from a query, using:
OutOfOrder:SetFlag([FieldName])
 
C

Crystal

Thanks for the reply.

That's what I did and it did not work:

OutofOroder: setflag([txt])

Result:
txt OutofOroder
1 *
2 *
3 *
6 *
9 *
I copied this function's code from a MSDN sample and it worked in report. But
it does not work when I use it in query. Can someone help me modify it?
[quoted text clipped - 16 lines]
End Function

Copy and paste that code (including the DIM Global as Variant) into a
Module.
Then call it from a query, using:
OutOfOrder:SetFlag([FieldName])
 
C

Crystal

I took the previous msg back. I copied the function to a brand new mdb and it
worked, partially though. How can I make the function not mark the very first
record. See example below. Thank you very much.

Field1 Outof order
1 *
2
3
5 *
7 *
Thanks for the reply.

That's what I did and it did not work:

OutofOroder: setflag([txt])

Result:
txt OutofOroder
1 *
2 *
3 *
6 *
9 *
[quoted text clipped - 6 lines]
Then call it from a query, using:
OutOfOrder:SetFlag([FieldName])
 
C

Crystal via AccessMonster.com

Can someone help me with modifying this function? It works fine the very
first time I use it after opening up the mdb. But afterwards, the function
always mark the very first row as out of sequence. I think it has to do with
"GlobalFlag = x", but I don't know how to fix it. Example is below.

Thank you very much!!

Field1 OutOfOrder
1 * (This one is not out of order and should not be
marked)
2
4 *
I took the previous msg back. I copied the function to a brand new mdb and it
worked, partially though. How can I make the function not mark the very first
record. See example below. Thank you very much.

Field1 Outof order
1 *
2
3
5 *
7 *
Thanks for the reply.
[quoted text clipped - 15 lines]
Then call it from a query, using:
OutOfOrder:SetFlag([FieldName])
 

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