|
||||||
|
|
Odd or Even By Richard Rost Determine if a Number is Odd or Even in Microsoft Access Microsoft Excel has two nice functions that make it easy to tell if a number is even or odd (IsEven, IsOdd). Access has no such functions, however using the MOD (Modulus, Modulo) operator, we can easily determine that status. Vishwanath asks, "Sir, how do you tell if a number is even or odd in Access?" MembersI'll show you how to recreate the IsEven and IsOdd functions from Excel in an Access VBA Module. You will also see how to print alternate even/odd page footers like you can do in Microsoft Word. Silver Members and up get access to view Extended Cut videos, when available. Gold Members can download the files from class plus get access to the Code Vault. If you're not a member, Join Today! Links
IntroIn this video, I will show you how to determine whether a number is odd or even in Microsoft Access by using the mod operator. We will look at how to apply this technique in queries to check fields like customer IDs, create calculated columns indicating odd or even status, and display custom labels such as "Even" or "Odd" using the IIF function. We will also discuss how the modulus operator works and explore practical ways to use it across your Access databases.TranscriptWelcome to another TechHelp video brought to you by AccessLearningZone.com. I am your instructor, Richard Rost. In today's lesson, I am going to show you how to tell whether a number is odd or even in Microsoft Access using the mod operator.Today's question comes from WishWonaut. He asks, Sir, how do you tell if a number is even or odd in Access? This is something that I know I have covered in my lessons. I know I have covered it a couple of times, but I cannot find it. I went through all of my outlines. I did a search on my site. I know I have talked about it, but I have not officially covered this in a lesson. So I figured since someone literally asked me today, this would make a perfect TechHelp video. If you are familiar with Microsoft Excel, Excel has two functions: is even and is odd, and that makes finding even or odd numbers very easy. Unfortunately, Microsoft Access has no such functions. However, we can use the modulus operator to determine if a number is odd or even. MOD is modulus or modulo, and that is equal to the remainder after an integer division. Now, if I take 10 divided by 3 with integer division, that is why my slash is a backward slash and not a normal forward slash that you usually see with regular division. This indicates integer division. If you have floating point numbers like doubles, like 5.2, that does not work with this. But 10 divided by 3 gives you 3. 3 times 3 is 9, so you have 1 left over. So that 1 is your modulus. 10 mod 3 equals 1. It is the remainder from the integer division. 10 divided by 2 with integer division is 5 with a 0 remainder. Therefore, 10 mod 2 equals 0. And that 0 is how you tell the number is even. And yes, it works for negative numbers too, and 0 is an even number. How do we use this inside of Microsoft Access? Let's say we have a list here of numbers, maybe our customer IDs: 1, 2, 3, 4, 5, 6, and so on. What if I wanted to determine if that customer ID is even? Let's use a query. You can use the mod operator in either a query or a form or a report or your VB code wherever you want to put it. Let's create a query, query design, bring in your customer table, bring in whatever number you want to check, customer ID, for example. If I put down here another value, let's call it x. That will be customer ID mod 2. Run the query and you will see all of the modulus results from that equation. You can see all of the even numbers have a 0 remainder. If you want to call that is even or is odd, just come over here. We will say is odd. So we will say is odd, colon, customer ID mod 2 like that. Is odd will be either true or false. Is even would just be the reverse of that. If you want to display the word even or odd, you could do something like this. You could use an if function, immediate if. You could say even or odd like this. If customer ID mod 2 equals 0, then it is an even number. Put even inside quotes or put odd. If you do not know how to use the immediate if function, IIF, I have other videos on that. They are free. You can check them out. I will put a link below. If I run that, you can see there is even or odd. That, in a nutshell, is how you tell whether a number is even or odd. Want to learn more? There is an extended cut members-only edition that goes into more detail about even or odd numbers. First, I will show you how to replicate the is even and is odd functions that Microsoft Excel has and use is even and is odd in all of your forms, reports, and queries. Using that information, I will show you how to print alternate page footers in your reports. If you duplex print a lot of reports and you want to have the page numbers go odd and even differently like Microsoft Word does, you can add that to your Microsoft Access reports as well. The odd numbers show up on the bottom right of the page and the even numbers on the bottom left. How do you become a member? Just click on that join button on my YouTube channel. You will see a list of membership options. Silver members and up get access to all of my extended cut TechHelp videos. Thanks for watching. I hope you learned something and these free TechHelp videos will keep coming. I am not going to get rid of them anytime soon. Make sure you subscribe to my channel. Subscribing is free and you will be able to get notifications every time I post a new video. Make sure to check out the forum on my website, 599cd.com/access-forum. If you have questions you would like to see answered, send them to me on my TechHelp page. There is all my good stuff: my blog, Facebook, Twitter, and YouTube of course. If you have not checked it out yet, watch my free Access Level 1 course. It is three hours long. It is the full tutorial. You can watch it for free on my website or on YouTube. If you like it, Level 2, which is another whole hour-long lesson, is only one dollar. Do me a favor. Take my course survey. Let me know what you thought. I know this is a free YouTube video, but I still like getting comments from people like you. Let me know exactly what you thought about my class. Once again, thanks for watching and we will see you next time. QuizQ1. What operator can you use in Microsoft Access to determine if a number is odd or even?A. Modulus (mod) operator B. Exponential (exp) operator C. Multiplication (*) operator D. Concatenate (&) operator Q2. What is the result of 10 mod 2 in Access? A. 2 B. 1 C. 0 D. 10 Q3. In Microsoft Access, if you have a field "CustomerID" and write "CustomerID mod 2", what does a result of 0 mean? A. The number is odd B. The number is prime C. The number is even D. The number is negative Q4. Which numbers will always have a 0 remainder when you divide them by 2 using integer division? A. Odd numbers B. Prime numbers C. Negative numbers D. Even numbers Q5. What does the MOD operator return? A. The quotient of two numbers B. The sum of two numbers C. The remainder after integer division D. The product of two numbers Q6. Which built-in functions exist in Excel but not in Microsoft Access for determining if a number is odd or even? A. ISFIRST and ISLAST B. ISINTEGER and ISFLOAT C. ISEVEN and ISODD D. ISNUM and ISSTR Q7. Where can you use the mod operator in Microsoft Access? A. Only in forms B. Only in tables C. In queries, forms, reports, or VB code D. Only in reports Q8. Which function can be combined with the mod operator to display "Even" or "Odd" as text in a query field? A. DLookup B. IIF (Immediate If) C. Sum D. Round Q9. What will the expression "IIF([CustomerID] mod 2 = 0, 'Even', 'Odd')" display for a CustomerID of 5? A. Even B. Prime C. Odd D. Error Q10. If you want to check for odd numbers using the mod operator in Access, which expression is correct? A. [Number] mod 2 = 1 B. [Number] mod 3 = 0 C. [Number] mod 2 = 0 D. [Number] + 2 = 1 Answers: 1-A; 2-C; 3-C; 4-D; 5-C; 6-C; 7-C; 8-B; 9-C; 10-A DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks. SummaryToday's video from Access Learning Zone focuses on how to determine if a number is odd or even in Microsoft Access using the mod operator.A viewer recently asked how to tell if a number is even or odd in Access. While I have definitely covered this topic in some of my previous lessons and discussions, I realized I had not given it a full dedicated lesson until now. Given that someone specifically asked me about it, I thought this was a perfect opportunity to address it directly in a TechHelp episode. For those familiar with Microsoft Excel, you might know there are built-in functions like ISEVEN and ISODD that can make this task very simple. However, Microsoft Access does not have those functions. Fortunately, we can use the modulus operator to achieve the same result. The modulus operator, often just called MOD, returns the remainder after integer division. To explain, if you perform integer division on 10 by 3, you get 3 because 3 goes into 10 three times, totaling 9, and 1 is left over. That 1 is your modulus. So, 10 mod 3 equals 1. Likewise, 10 mod 2 would be 0, since 2 divides evenly into 10 with no remainder. That 0 is the key – if a number mod 2 equals 0, it is even. This technique works with negative numbers as well, and zero is considered even. Now, let's look at how you can put this into practice in Microsoft Access. Suppose you have a list of numbers, such as customer IDs. If you want to check whether those IDs are even, set up a query. You can use the mod operator in queries, forms, reports, or VBA code. In your query design, add the relevant table and bring the field you want to check, for example, CustomerID. Create a calculated field where you simply calculate CustomerID mod 2. If you run this query, you will see the results for each number. Even numbers will yield 0. If you want to label the field as "IsOdd," you can use a calculated column. The value will be either true or false depending on the result. Reversing the logic will give you "IsEven." If you want the output to display the words "even" or "odd," use the Immediate If (IIF) function, which works similarly to Excel's IF function. For example, you would have something like: if CustomerID mod 2 equals 0, then return "Even"; otherwise, return "Odd." If you are not familiar with the IIF function, I have separate videos on that topic, and I will link to one for you. Using this method, you can easily determine if a number is odd or even within Microsoft Access. If you would like to go further, today's extended cut for members covers in more depth how you can actually recreate the ISEVEN and ISODD functions from Excel and use those custom functions everywhere in your Access database, including forms, reports, and queries. Additionally, I cover how to add alternate page footers in your reports based on whether the page is odd or even. This can be especially useful if you print duplex reports and wish to have footer text or page numbers displayed on opposite sides for odd and even pages, similar to how Microsoft Word handles it. If you are interested in these extra tutorials, you can become a member by joining my YouTube channel as a Silver member or higher, which grants you access to all of my extended cut TechHelp videos. Thank you for watching. I appreciate your support, and I plan to continue creating these free TechHelp videos for the foreseeable future. Be sure to subscribe to my channel to get notifications when new lessons are posted. Also, check out the forum on my website if you have questions or want to participate in community discussions. If you have topics you want me to cover, submit a question through my TechHelp page. All of my main resources, blog, and social links are available there as well. If you are new to Access, I recommend watching my free Access Level 1 course available on my website and on YouTube. It is a comprehensive three-hour tutorial. If you enjoy it, consider taking Level 2 for just one dollar. Please fill out my course survey and let me know your thoughts. Your feedback is valuable even for free YouTube content like this. For step-by-step instructions on everything discussed here, you can find the complete video tutorial on my website at the link below. Live long and prosper, my friends. Topic ListUsing the MOD operator to determine odd or even numbersInteger division explanation in Microsoft Access Building a query to check if numbers are odd or even Using the MOD operator in an Access query field Creating calculated fields to show MOD results Displaying "true" or "false" for odd or even values Using the IIF function to display "Even" or "Odd" text |
||||
|
| |||
| Keywords: TechHelp Access odd or even or odd mod modulus modulo integer division iif iseven isodd alternate page footers word even page odd page PermaLink Odd or Even? in Microsoft Access |