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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Odd Even Function for field in query 1

Status
Not open for further replies.

ghloid

IS-IT--Management
Mar 11, 2002
85
US
Uggh, another one of those crazy problems which I think would have a simple answer.

I have a query where one column of data (the field is called IssueNo) contains a number. I want to create another field in that query called OddEven which will display some text if the IssueNo number is an odd number and some other text if it is even. I believe this can be accomplished through use of a VBA public function in the query somehow (I know you can use VBA public functions for the criteria of a query at any rate). So, I came up with a quick public function trying to accomplish this. Here's the simple code:

Public Function OddChk(TheNumber) As Byte

If TheNumber And 1 Then
TheNumber = 1
Else
TheNumber = 0
End If

End Function

So, if you put in the field section of my query something like:

OddEvenChk: OddChk([IssueNo])

then I would THINK you would get back a 1 for the odd numbered issues and a 0 for the even numbered. But of course I don't get that, I only get zeros down the column.

Actually, it would be BETTER if I could have the function somehow return TRUE for the odd numbers and False for the even, but I can't figure out how to do that in the code. If I could, I would put something like this in the field column:

OddEvenChk: iif(OddChk([IssueNo] = True, "Odd", "Even")

Boy wouldn't that be nice.

Anyway, seems like this should be possible, or they should have created a function for this already. I saw an "IsOdd" workbook function in the help, but that didn't seem to work for me (Access just couldn't recognize the function).

Anyone have any ideas out there? I do appreciate any help that can be offered.

Thanks!!
 
Or just a field in your query
[tt]
IIF ( [field] MOD 2 = 0, "Even", "Odd" ) As [OddEven]
[/tt]
 
Ahh, so sweet and simple. I knew there was an easy way to do it. I never knew about that MOD 2 = 0 function though. Looks pretty interesting. I'm giving you a star for such a great quick response.

THANKS!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top