Go Back   Access World Forums > Microsoft Access Discussion > General

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 10-09-2019, 01:32 PM   #1
kitty77
Newly Registered User
 
Join Date: May 2019
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
kitty77 is on a distinguished road
strDocName Error

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...

kitty77 is offline   Reply With Quote
Old 10-09-2019, 01:45 PM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 4,566
Thanks: 50
Thanked 1,047 Times in 1,028 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: strDocName Error

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.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 10-09-2019, 01:45 PM   #3
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,350
Thanks: 112
Thanked 2,841 Times in 2,591 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: strDocName Error

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?

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 10-09-2019, 01:48 PM   #4
kitty77
Newly Registered User
 
Join Date: May 2019
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
kitty77 is on a distinguished road
Re: strDocName Error

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...
kitty77 is offline   Reply With Quote
Old 10-09-2019, 02:02 PM   #5
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 10,350
Thanks: 112
Thanked 2,841 Times in 2,591 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: strDocName Error

Try
If...ElseIf...ElseIf...Else...End If
OR use Select Case notation

Debug.print strDocName as well as strWhere as a check
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 10-09-2019, 02:03 PM   #6
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 4,566
Thanks: 50
Thanked 1,047 Times in 1,028 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: strDocName Error

Quote:
Originally Posted by kitty77 View Post
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?
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 10-09-2019, 04:45 PM   #7
kitty77
Newly Registered User
 
Join Date: May 2019
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
kitty77 is on a distinguished road
Re: strDocName Error

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.

kitty77 is offline   Reply With Quote
Old 10-09-2019, 04:54 PM   #8
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 4,566
Thanks: 50
Thanked 1,047 Times in 1,028 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: strDocName Error

Quote:
Originally Posted by kitty77 View Post
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.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 10-09-2019, 05:21 PM   #9
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 4,566
Thanks: 50
Thanked 1,047 Times in 1,028 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: strDocName Error

Quote:
Originally Posted by kitty77 View Post
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
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 10-09-2019, 05:59 PM   #10
Micron
AWF VIP
 
Join Date: Oct 2018
Location: Ontario, Canada
Posts: 932
Thanks: 10
Thanked 189 Times in 179 Posts
Micron has a spectacular aura about Micron has a spectacular aura about
Re: strDocName Error

Quote:
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.
__________________
Sometimes I just roll my eyes out loud...
Windows 10; Office 365 (Access 2016)

Last edited by Micron; 10-10-2019 at 03:59 AM.
Micron is offline   Reply With Quote
Old 10-09-2019, 10:28 PM   #11
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,383
Thanks: 68
Thanked 2,698 Times in 2,583 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: strDocName Error

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"
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 10-10-2019, 04:07 AM   #12
Micron
AWF VIP
 
Join Date: Oct 2018
Location: Ontario, Canada
Posts: 932
Thanks: 10
Thanked 189 Times in 179 Posts
Micron has a spectacular aura about Micron has a spectacular aura about
Re: strDocName Error

Quote:
Originally Posted by arnelgp View Post
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.
__________________
Sometimes I just roll my eyes out loud...
Windows 10; Office 365 (Access 2016)

Last edited by Micron; 10-10-2019 at 04:10 AM. Reason: clarification
Micron is offline   Reply With Quote
Old 10-10-2019, 09:15 AM   #13
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 28,133
Thanks: 15
Thanked 1,570 Times in 1,492 Posts
Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all
Re: strDocName Error

@Micron,
If a <> b will result in FALSE if either a or b is null. No test of a null value will ever return true except IsNull()

@Kitty,
Do not use parentheses unless they are needed. Having them in an expression just causes confusion when they are serving no purpose.

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

should be

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

Also, don't use square brackets for the same reason. They are simply eye clutter and distracting.

Now we get to the rules of precedence which is what you need to understand to create compound conditions. In logical operations the order is NOT, AND, OR

If all the conditions use the same relational operator
either:
a and b and c and d
OR:
a or b or c or d

Then the order is irrelevant. The result will be the same regardless of the order in which the conditions are evaluated. a and b is exactly the same result as b and a.

The tricky part is when you need to mix operators.
a or b and c or d
Now we have to perform the conditions based on the order of precedence so AND happens first. To explain this, I will add parentheses to show how the statement is evaluated
a or (b and c) or d
Once the AND is handled, we now have three values instead of four and they are related by OR since we evaluated the AND away.

Rather than depend on you or your readers understanding how the compiler will evaluate complex expressions, it is best to always use parentheses when you use different operators. Perhaps you wanted
a or b and c or d
to be evaluated as
(a or b) and (c or d)
That would most likely give a different result than the default interpretation. Or how about:
((a or b) and c) or d
As you can see, there are several different results and only YOU know what you want.
__________________
Bridge Players Still Know All the Tricks

Last edited by Pat Hartman; 10-11-2019 at 04:25 PM.
Pat Hartman is offline   Reply With Quote
Old 10-10-2019, 01:13 PM   #14
Micron
AWF VIP
 
Join Date: Oct 2018
Location: Ontario, Canada
Posts: 932
Thanks: 10
Thanked 189 Times in 179 Posts
Micron has a spectacular aura about Micron has a spectacular aura about
Re: strDocName Error

Quote:
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
Micron is offline   Reply With Quote
Old 10-10-2019, 07:57 PM   #15
kitty77
Newly Registered User
 
Join Date: May 2019
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
kitty77 is on a distinguished road
Re: strDocName Error

Thanks for all the good info on this subject. Got it working!!

kitty77 is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question strSQL = Run Time Error 3075 Syntax Error Missing Operator in qry Expr maxsun08 General 4 07-27-2012 06:39 AM
Error "Run-time error '1004': General ODBC Error D4WNO General 1 07-19-2012 07:42 AM
Error 3734 (share mode error) appearing in error guy- Modules & VBA 2 09-28-2011 02:02 AM
A question about the error message "Run-time error '3061' Too few parameters, Expecte dariyoosh Modules & VBA 7 03-12-2010 06:26 AM
Run time error 3075 - syntax error (missing operator) in query expression puskardas Modules & VBA 8 06-30-2008 07:35 PM




All times are GMT -8. The time now is 10:57 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World