Gasman
Enthusiastic Amateur
- Local time
- Today, 18:35
- Joined
- Sep 21, 2011
- Messages
- 16,556
Now crossposted at https://www.utteraccess.com/topics/2066757?post=unread
I seems that no matter what I post, I'm going to get criticized instead of helped.Now crossposted at https://www.utteraccess.com/topics/2066757?post=unread
I would love to switch to VBA. I'm never written one before. What is my first step or should i watch videos?I second the motion.
@dullster Assume that your already-somewhat-complex statement will grow in complexity over time. A VBA function will make it much easier to read, edit document and maintain. As soon as I have significant trouble reading a statement like that I switch to VBA , if there's no other reason not to. If the Access IDE allowed you to format code in those situations and preserved that formatting and coloring, it might be a different story...
I hate to add to your discomfort but the essential problem is the cross-posting. The experts here are all volunteers. No one is getting paid to help you. When you can't be bothered to wait for an answer on a single forum and so post in another, you start a second group of experts looking at your problem. This wastes the time of the both groups and shows great disrespect for their efforts on YOUR behalf. That is why you are getting complaints. Plus your questions tend to be vague which always makes our task harder.I seems that no matter what I post, I'm going to get criticized instead of helped.
I marked it as solved which I thought was what I was supposed to do but If I'm supposed to do something else, please let me know. I did that because one person just keeps making rude comments about doing it sql, which i don't know how to do and that really is their only contribution which just keeps adding to the thread. When I try to clarify, they continue making more non helpful comments so I'm spinning my wheels too. I was just learning to navigate the forum and apparently made some mistakes and I'll own that.@dullster - I speak to you know in my role as a moderator. I saw your complaint and I think I understand it.
One of the comments made in this thread is that you cross-posted a question without notification. What that specifically means is that you posted a question in more than one site and didn't tell us that you had done so. There is a solution on the cross-posting site, but you have failed to notify us of that solution being available.
Let me be clear: It is not illegal to cross-post. However, we consider it somewhat insulting and unappreciative to do so without telling us. The reason is that, as Pat has explained, we volunteer our time to help people. We have seen many times that people get frustrated by not getting an answer (or at least not getting an answer they like), so they resort to asking around other specialty sites like ours. It might seem that you would have a better chance getting an answer by putting your question on a second site. But many of our experts post on multiple sites and recognize your problem because they saw it on another site.
Cross-posting is a sign of a couple of problems at once.
First, you don't think you are being helped. But if there is either a language barrier OR a nomenclature barrier, it might be that we are facing the REAL problem, which I'm beginning to think is applicable here. From the movie Cool Hand Luke, "What we have here is a failure to communicate." Your descriptions make it difficult for us to understand the problem. You keep on saying you get an error. Forgive me for this, but the error is in you stating it that way. You should say "When I do x y z I get error nnnn, Syntax error" I.e. tell us what you did and the error you got. Let me give you an analogy. You go to the doctor and you tell him/her "I am not feeling well." So the doctor asks questions and - due to confusion, perhaps - you don't provide anything more specific. Do you really expect the doctor to identify what is wrong? Without some indication of HOW you know something is wrong, we are as in the dark as you are.
Second, you don't realize OUR situation, where we get literally hundreds of posts in a busy day and need to respond to them. BUT this is truly a world-wide forum with members in Japan and the Philippines, Australia and New Zealand, North and South America, most of the European countries, Africa, and many nations on the Asian Continent. Sometimes you might have to wait for help due to time zone differences. So your impatience ends up alienating folks who really DO want to help you.
When you cross-post without telling us about it, then something happens that REALLY irks us. You get an answer on the other site (which HAS happened) and you don't tell us the problem has been solved (which also HAS happened), thus letting us spin our wheels on something that is no longer unsolved. That is disrespectful. If you believe you are being disrespected, please consider it as a reflection of your own behavior.
I would love to switch to VBA. I'm never written one before. What is my first step or should i watch videos?
Is this too simple?I'd say make a post with a simple example of what you'd want to make and I'll help show a VBA version of it. Just for time's sake, a simple one
IIf([tblEmployees].[Marital Status]=1 And [Basic Salary]>25727,[tblEmployees].[Basic Salary]-(([tblEmployees].[Basic Salary]-[Lower])*0.2)-([Exemption credit]),IIf([tblEmployees].[Marital Status]=2 And [Basic Salary]>17780,[tblEmployees].[Basic Salary]-(([tblEmployees].[Basic Salary]-[Lower])*0.12)-([Exemption credit])))
IIf([tblEmployees].[Marital Status]=1,[tblEmployees].[Basic Salary]>[tblpayrolltaxes].[Lower],([tblEmployees].[Basic Salary]-[tblpayrolltaxes].[Lower]), IIf([tblEmployees].[Marital Status]=2,[tblEmployees].[Basic Salary]>[tblpayrolltaxes].[Lower],([tblEmployees].[Basic Salary]-[tblpayrolltaxes].[Lower],0))
I tweaked you earlier on not showing the error message but you actually had it. It just didn't stand out. So for the tweak, I apologize.I get this error, The expression you entered has a function containing the wrong number of arguments. What am i doing wrong?
Marital Status is from table [Marital Status] Married=1, Single=2 Short text and is required; Basic Salary is from [tlbEmployees] Currency is required; Lower is from [tblpayrolltaxes] Currency is required; [Exemption credit] if a calculated Currency field in the [QryStateTax]Good, I will write up a potential vba function if some overachiever type doesn't try to beat me to it, tomorrow morning or later tonight
What are the reliable datatypes of input columns Marital Status, Basic Salary, Lower and Exemption credit? I was kind of guessing Whole number, Decimal/double to start with, not sure about the last two. And can they be null potentially - as in, do you allow nulls at the table level?
I didn't know that the IIF only condones three arguments. Probably exactly my problem, thus why I need to graduate to vba. Thank you.You deserve at least a direct answer or two. From your first post:
Code:IIf([tblEmployees].[Marital Status]=1,[tblEmployees].[Basic Salary]>[tblpayrolltaxes].[Lower],([tblEmployees].[Basic Salary]-[tblpayrolltaxes].[Lower]), IIf([tblEmployees].[Marital Status]=2,[tblEmployees].[Basic Salary]>[tblpayrolltaxes].[Lower],([tblEmployees].[Basic Salary]-[tblpayrolltaxes].[Lower],0))
I tweaked you earlier on not showing the error message but you actually had it. It just didn't stand out. So for the tweak, I apologize.
The specification for IIF is IIF( criteria-expression, true-result-expression, false-result-expression) where you are trying to pick between two alternatives to get one (and only one) of two possible answers. The syntax rules are that the criteria-expression SHOULD resolve to either a TRUE or a FALSE result. Then the function returns the result of evaluating either the true-result-expression or the false-result-expression. The two result-expressions should in theory BOTH return the same data type, which will become the effective data type of the IIF result. Actually, most intrinsic functions (like IIF) return variant data types, so it doesn't really matter what data type those two expressions return.
The way to analyze this kind of error (involving functions) most often starts by grouping expression elements by parentheses and commas.
IIf( [tblEmployees].[Marital Status]=1, <== will return True/False - so meets criteria-expression requirement.
[tblEmployees].[Basic Salary]>[tblpayrolltaxes].[Lower], <== because of the ">", a relation operator, this expression will return True/False.
([tblEmployees].[Basic Salary]-[tblpayrolltaxes].[Lower]), <== will return a number based on data type of [Basic Salary] and [Lower] which means the two result expressions don't match in datatype. One is T/F, the other is numeric. That is already not a good thing, though VBA can handle that by doing something called "type coercion".
Even more important, that false-result-expression ends with a comma. which signals VBA that another argument is coming. Except that you have already had three arguments, which is all that IIF condones. Thus your error "wrong number of arguments."
I took one of your expressions and began creating a function with comments about the process I go through in your other thread. You need to start the conversion and a new thread when you begin to stumble (we all do).I didn't know that the IIF only condones three arguments. Probably exactly my problem, thus why I need to graduate to vba. Thank you.