strDocName Error

kitty77

Registered User.
Local time
Today, 15:37
Joined
May 27, 2019
Messages
719
I'm using the following code in a command button.

Dim strDocName As String
Dim strWhere As String
If ([Mid] = "111") Then strDocName = "Report1"
If ([Mid] = "222") Then strDocName = "Report2"
If ([Mid] = "222") Then strDocName = "Report1"
strWhere = "[Mrecordid]=" & Me!Mrecordid
DoCmd.OpenReport strDocName, acViewReport, , strWhere

I'm getting the following error: The action or method requires a report name argument.

What am I doing wrong?

Thanks...
 
Hi. Perhaps none of the checks ([Mid]="111" or "222") was valid. For example, what if [Mid] was "333?"


Maybe you should assign a default report name or check first if there's a report name assigned before trying to open it.
 
This may be a typo but both lines can't be correct:
Code:
If ([Mid] = "222") Then strDocName = "Report2"
If ([Mid] = "222") Then strDocName = "Report1"

Try adding the line Debug.Print strWhere before DoCmd.OpenReport ...
Does the output seem correct?
 
Sorry, yes was a typo...

It looks like it does not like or can't handle multiple questions. When I break it done, it works. Here is what I really want.

If ([Mid] <> "aaa") And ([Mst] = "bbb") And ([M1] <> [M2]) Then strDocName = "Report"

Hope this makes sense...
 
Try
If...ElseIf...ElseIf...Else...End If
OR use Select Case notation

Debug.print strDocName as well as strWhere as a check
 
Sorry, yes was a typo...

It looks like it does not like or can't handle multiple questions. When I break it done, it works. Here is what I really want.

If ([Mid] <> "aaa") And ([Mst] = "bbb") And ([M1] <> [M2]) Then strDocName = "Report"

Hope this makes sense...
Hi. How about telling us what you want to check for using plain words, and we'll try to convert it into code for you?
 
I think basically, how do put several arguments together?
If something = something, If something <> something, etc...

Say four or five arguments. All these arguments helps me select the proper report to print.

Maybe an example of several arguments together would be helpful.
 
I think basically, how do put several arguments together?
If something = something, If something <> something, etc...

Say four or five arguments. All these arguments helps me select the proper report to print.

Maybe an example of several arguments together would be helpful.

Hi. If I try to explain to you how to combine multiple conditions together, you will still be left interpreting it to apply to your particular situation. Sometimes, it might be easier to actually give an example that applies to your situation because it would make it easier for you to understand it and then apply what you learned to your other scenarios. We just need an English translation of what you want the code to do. We'll convert it to code speak for you.
 
I think basically, how do put several arguments together?
If something = something, If something <> something, etc...

Say four or five arguments. All these arguments helps me select the proper report to print.

Maybe an example of several arguments together would be helpful.

Okay, see if this helps any. There are several ways to check for multiple conditions. For example.

Code:
If condition1 Then
  'do stuff
ElseIf condition2 Then
  'do stuff
...
End If

Or, if you need multiple conditions met at the same time, it might look like.

Code:
If condition1 AND conditions2 AND condition2 Then
...
End If
 
It looks like it does not like or can't handle multiple questions
"It" certainly can. In my experience the issue is almost always not constructing an expression in a manner that is conducive to how the logic is processed by computer. Not so much when dealing with multiple AND operators as much as when the OR operator comes in to play.

Guaranteed that this will evaluate to True
6<>5 and 3=3 and 7<>8

EDIT - I let the posts about expressions divert me from the message you got. I interpret it that your value for the report name is invalid. It doesn't exist as named. Check spelling. Colin alluded to that in his post.
 
Last edited by a moderator:
on the expression:

If ([Mid] <> "aaa") And ([Mst] = "bbb") And ([M1] <> [M2]) Then strDocName = "Report"

if any variables are empty, it would result to Null.
and you can't compare a Null to any value, hence resulting to False.
better add a null string, then compare:

If ([Mid] & "" <> "aaa") And ([Mst] & "" = "bbb") And ([M1] & "" <> [M2] & "") Then strDocName = "Report"
 
If ([Mid] <> "aaa") And ([Mst] = "bbb") And ([M1] <> [M2]) Then strDocName = "Report"
if any variables are empty, it would result to Null.
and you can't compare a Null to any value, hence resulting to False.
better add a null string, then compare:
Only half true. Since you can't compare anything to Null, the result of the expression can only be Null, not false. Your empty string can work for <> comparisons, but never for = and be true, thus that expression will always evaluate to false anyway because "" will never equal bbb. Besides, the error message suggests that in all (or at least some) cases, the report variable is an empty string and that is what is being passed to the open report command. That means that none of the expressions are true, but they may all be Null too.
 
Last edited by a moderator:
If a <> b will result in FALSE if either a or b is null. No text of a null value will ever return true except IsNull()
Not that I ever said "no text of a Null will ever return true" because I have no idea what that means. I've never heard of "a text of a Null" but as for the rest, did you test?

?6<>5 and 3=null and 7<>9
Null
?6<>Null and 3=3 and 7<>9
Null
?6<>5 and 3=3 and 7<>Null
Null
 
Thanks for all the good info on this subject. Got it working!!
 
You're not telling me anything that I don't already know.
Maybe this is all just semantics, but I'm not going to agree that "Null is equivalent to "Not True"" because Null is not equal to anything. Equivalent means equal or corresponding to. Null is neither equivalent, corresponding or equal to anything. I'm sure I don't have to tell you that, so I mention it for the benefit of others. Your example is obvious as I've just alluded to: b is not equal to null, thus the expression evaluates to null. I think I already showed that with my immediate window post results so I don't get why you posted that.

Still would like to know what a "text of a null" is. Or let's just move on?
 
the result is treated as false when used in a where clause
Do you have an example of that; specifically how you would use Null in a Where clause? In my experience, if you put =Null in a query design you will get nothing because as we agree, null is not equal to anything. If you put Null in the query, Access will convert that to Is Null, which is a function. If you try to do this in vba, you'll get an error.

So how would you use null in a where clause as you seem to be saying?
 
Do you have an example of that; specifically how you would use Null in a Where clause? In my experience, if you put =Null in a query design you will get nothing because as we agree, null is not equal to anything. If you put Null in the query, Access will convert that to Is Null, which is a function. If you try to do this in vba, you'll get an error.

So how would you use null in a where clause as you seem to be saying?
Hi. Pardon me for jumping in, but here's what I just tried...

Code:
SELECT * FROM TableName WHERE 1 = TempVars!Test
 
Hi. Pardon me for jumping in, but here's what I just tried...

Code:
SELECT * FROM TableName WHERE 1 = TempVars!Test
A little supporting info would help. What is the value of TempVars!Test? Null, empty string or some value? What was the result of that statement test?
 
A little supporting info would help. What is the value of TempVars!Test? Null, empty string or some value? What was the result of that statement test?
Sorry. I knew I should have known better than to interrupt a good discussion. I'll go ahead and let Pat explain her side further, but here's what I was getting from the thread. If you enter the following SQL, you get all the records back:
Code:
SELECT * FROM TableName WHERE 1=1
And if you enter the following SQL, you get none back.
Code:
SELECT * FROM TableName WHERE 1=Null
However, as you have pointed out, the above will internally get changed to this.
Code:
SELECT * FROM TableName WHERE 1 Is Null
So, from what Pat was saying, I offered the following SQL.
Code:
SELECT * FROM TableName WHERE 1=TempVars!AnyNonExistingTempVar
If you try the above, you don't need to declare any TempVars first nor do you need to initiate it to anything at all. A call to a non-existing or non-initiated TempVar will return a Null value. So, using the above SQL, I can't say it's getting changed to an Is Null condition but maybe an actual 1=Null one. In either case, the resulting query shows no records, which is equivalent to having a False Where Condition.
 
I'm not sure what point you were making. Of course, anything like this gives the same result

Code:
SELECT * FROM TableName WHERE 1=0;
 
Last edited:

Users who are viewing this thread

Back
Top Bottom