473,503 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

docmd.OpenReport - problem with Where Clause

Hi, i am trying to open a report based on values picked in a form but
get stuck with one of the values. I have a feeling it has to do with
the yes/no datatype but am not sure since I am quite new to access
VBA. I'm using Access2003

Below is my code extract. The tblWelderQualification.Stamped field is
a yes/no field, I want to show records that have a "TRUE" value when
the checkbox on the form is ticked. When I run the code, I get the
parameter value window popup asking for
"tblWelderQualification.Stamped". If i type "True" then the report
works, if left blank it fails. I dont want to have to type anything
and would like it to work as it does for the other fields.

Any ideas??

stWhereClause = "(((tblWelderQualification.[Test Number]) Like
IIf(Forms!frmTestSubform!chkTestNo=True,Forms!frmT estSubform!
TestNo,'*')) And " & _
"((tblWelders.[Welder ID]) Like IIf(Forms!frmTestSubform!
chkWID=True,Forms!frmTestSubform!wID,'*')) And " & _
"((tblWelderQualification.[WPS No]) Like IIf(Forms!frmTestSubform!
chkWPS=True,Forms!frmTestSubform!subWPS,'*')) And " & _
"((tblWelderQualification.Stamped) Like IIf(Forms!frmTestSubform!
chkCertified='True','True','*')) And " & _
"((tblWelderQualification.Project) Like IIf(Forms!frmTestSubform!
chkProject=True,Forms!frmTestSubform!txtProject,'* ')))"
stDocName = "rptTest"
DoCmd.OpenReport stDocName, acPreview, , stWhereClause

Mar 5 '07 #1
3 6437
ru*******@gmail.com wrote:
Hi, i am trying to open a report based on values picked in a form but
get stuck with one of the values. I have a feeling it has to do with
the yes/no datatype but am not sure since I am quite new to access
VBA. I'm using Access2003

Below is my code extract. The tblWelderQualification.Stamped field is
a yes/no field, I want to show records that have a "TRUE" value when
the checkbox on the form is ticked. When I run the code, I get the
parameter value window popup asking for
"tblWelderQualification.Stamped". If i type "True" then the report
works, if left blank it fails. I dont want to have to type anything
and would like it to work as it does for the other fields.

Any ideas??

stWhereClause = "(((tblWelderQualification.[Test Number]) Like
IIf(Forms!frmTestSubform!chkTestNo=True,Forms!frmT estSubform!
TestNo,'*')) And " & _
"((tblWelders.[Welder ID]) Like IIf(Forms!frmTestSubform!
chkWID=True,Forms!frmTestSubform!wID,'*')) And " & _
"((tblWelderQualification.[WPS No]) Like IIf(Forms!frmTestSubform!
chkWPS=True,Forms!frmTestSubform!subWPS,'*')) And " & _
"((tblWelderQualification.Stamped) Like IIf(Forms!frmTestSubform!
chkCertified='True','True','*')) And " & _
"((tblWelderQualification.Project) Like IIf(Forms!frmTestSubform!
chkProject=True,Forms!frmTestSubform!txtProject,'* ')))"
stDocName = "rptTest"
DoCmd.OpenReport stDocName, acPreview, , stWhereClause
A Yes/No actually stores -1 and 0 for True and False, but you can apply
criteria using True and False, but not 'True' and 'False' as you are.

Also, Like is only appropriate for text fields. For Yes/No, Numeric, and
Dates you should stick with "=".

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Mar 5 '07 #2
Tried changing things to the below, but still get the same problem.

stWhereClause = "(((tblWelderQualification.[Test Number]) Like
IIf(Forms!frmTestSubform!chkTestNo=True,Forms!frmT estSubform!
TestNo,'*')) And " & _
"((tblWelders.[Welder ID]) Like IIf(Forms!frmTestSubform!
chkWID=True,Forms!frmTestSubform!wID,'*')) And " & _
"((tblWelderQualification.[WPS No]) Like IIf(Forms!frmTestSubform!
chkWPS=True,Forms!frmTestSubform!subWPS,'*')) And " & _
"((tblWelderQualification.Stamped)=IIf(Forms!frmTe stSubform!
chkCertified=True,True,'*')) And " & _
"((tblWelderQualification.Project) Like IIf(Forms!frmTestSubform!
chkProject=True,Forms!frmTestSubform!txtProject,'* ')))"

Also, in the query where I copied this from. If I change "Like" to
"=" on the "stamped" field condition then I get the following error
when I try to view in datasheet view.

"The expression is typed incorrectly, or it is too complex to be
evaluated. For example, a numeric expression may contain too many
complicated elements. Try simplifying the expression by assigning
parts of the expression to variables."

If I change it back to "Like" then it works fine.

I also tried removing the where clause in the OpenReport and adding a
filter, this being the query from which I got the where statement.
This produced the same problem.

Could it be the case that because the "stamped" field is not in the
report I am trying to open is the reason i am getting this error?

Mar 6 '07 #3
ru*******@gmail.com wrote:
Tried changing things to the below, but still get the same problem.

stWhereClause = "(((tblWelderQualification.[Test Number]) Like
IIf(Forms!frmTestSubform!chkTestNo=True,Forms!frmT estSubform!
TestNo,'*')) And " & _
"((tblWelders.[Welder ID]) Like IIf(Forms!frmTestSubform!
chkWID=True,Forms!frmTestSubform!wID,'*')) And " & _
"((tblWelderQualification.[WPS No]) Like IIf(Forms!frmTestSubform!
chkWPS=True,Forms!frmTestSubform!subWPS,'*')) And " & _
"((tblWelderQualification.Stamped)=IIf(Forms!frmTe stSubform!
chkCertified=True,True,'*')) And " & _
"((tblWelderQualification.Project) Like IIf(Forms!frmTestSubform!
chkProject=True,Forms!frmTestSubform!txtProject,'* ')))"
Get rid of all the check boxes and use criteria like this...

WHERE (TestNumber = Forms!frmTestSubform!TestNo
OR Forms!frmTestSubform!TestNo Is Null)

That returns all rows if the control on the form is empty and only matching rows
when the control on the form has a value in it. (Much simpler)

repeat for other criteria
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Mar 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3831
by: Andrew | last post by:
Hi All: I am using Access2000 and I find that the command to open an Access report in preview mode is very slow: DoCmd.OpenReport rptABC, acViewPreview, "", "" The scenario is this: - The...
1
2910
by: Filips Benoit | last post by:
Dear All, DoCmd.OpenReport RPT_TEST, A_PREVIEW, QueryAsFilter doesn't work correctly in A97 but works OK in A2K. Is this a bug for A97 ? Filip
1
2135
by: LoopyNZ | last post by:
Hi there, I've converted an Access 97 front end to Access 2000, but when I try to run a VBA DoCmd.OpenReport (e.g. DoCmd.OpenReport "rpt_programme_listing") line, Access completely crashes...
3
2724
by: news.onet.pl | last post by:
Hello! I have a question concerning to open the reports. I know that DoCmd.OpenReport is a obsolete form of opening the reports, but how to implement opening reports in VB using another VB code?...
3
7762
by: enough2Bdangerous | last post by:
access runtime error 3011 on docmd.openreport -------------------------------------------------------------------------------- Access database (file format 2002-2003) generates reports with...
4
9443
by: Simon | last post by:
Dear reader, The syntax for Docmd.OpenReport is: OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs) Example The following example prints Sales Report while...
4
6043
by: robtyketto | last post by:
Greetings, I originally used a button on a from created via the button wizard (access 2007) to run my report which was based on a query. Since I wanted to add some validation I removed the...
5
2406
by: scottbouley | last post by:
Maybe I'm missing something or perhaps there's another way to do this. I'm trying to allow the user to preview and print an invoice as they are exiting from the New Sale form. However, the preview...
4
6634
by: gazza10001 | last post by:
Hi i hope you can help my company uses access and has modified for its needs usually what happens is you serach for the invoice by its number and then it brings all the information up such as...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.