473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DoCmd.OpenReport trouble

I'm trying to open a report using the following code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrintSample_Click()
  2.     Dim strWhere As String
  3.     strWhere = Nz([Forms]![frmReports]![cboCity], "'" & "*" & "'") & _
  4.                " AND " _
  5.                & Nz([Forms]![frmReports]![cboNeighborhood], "'" & "*" & "'") & _
  6.                " AND " _
  7.                & Nz([Forms]![frmReports]![cboRooms], "'" & "*" & "'")
  8.     DoCmd.OpenReport "rptSampler", acViewPreview, , strWhere
  9. End Sub
I get prompted for a parameter (the name of the city) even when info is entered on the form, if I re-enter the parameter it opens the report ignoring the strWhere, and if I don't re-enter the parameter it opens the report without records.

Any idea what's wrong?
Jul 23 '12 #1
9 1949
Rabbit
12,516 Expert Mod 8TB
1) If it's just the cboCity that's popping up the parameter box, then check the name of the control.

2) If it's all of them, check the name of the controls and the form.

3) If it's not actually cboCity and some other city parameter, check the parameters in the query.

4) The reason your strWhere is being ignored is because it's coded incorrectly, you're not telling it which field to filter on.

For example, if your city is Los Angeles:
Expand|Select|Wrap|Line Numbers
  1. What you have:
  2. strWhere = "Los Angeles"
  3.  
  4. What you need:
  5. strWhere = "cityField = 'Los Angeles'"
Jul 23 '12 #2
dsatino
393 256MB
First, see Rabbits response...

Your NZ() function is also not going to get you what you want if your fields are null. It looks like you are trying to get any city if the city is blank, but you under your current syntax you will return no results because you are telling it to look for cities names "*".
Jul 23 '12 #3
@Rabbit
Would this do the job?
Expand|Select|Wrap|Line Numbers
  1. "City = '[Forms]![frmReports]![cboCity]'"
@dsatino
What is the proper syntax?
Jul 23 '12 #4
Rabbit
12,516 Expert Mod 8TB
It will not. The engine won't have access to the form values. You need to use your current approach, you just need to tell it what field to filter on.
Jul 23 '12 #5
How would I do that?
Jul 23 '12 #6
Rabbit
12,516 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. strWhere = "cityField Like '" & Nz([Forms]![frmReports]![cboCity], "*") & "'"
Jul 23 '12 #7
I tried your suggestion
Expand|Select|Wrap|Line Numbers
  1. strWhere = " A.City Like '" & Nz([Forms]![frmReports]![cboCity], "*") & "'"
, it ended in a type mismatch error.

Giving Los Angeles instead of 'Los Angeles'.
Jul 26 '12 #8
Rabbit
12,516 Expert Mod 8TB
That's an easy error message to troubleshoot. If there's a type mismatch, then you need to check the data types to see which one isn't matching up.
Jul 26 '12 #9
Ok I think I got it, I had added another filter using the AND keyword Should have been & " AND " &.
Jul 26 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
2
by: Jonathan Goldman | last post by:
Hi- I have a relatively simple report that I open in an Access '97 VBA procedure, using the Docmd.OpenReport "rptName", acViewNormal syntax. The problem is that doing this usually crashes...
1
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
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...
1
by: JohnM | last post by:
I don't seem to be able to get opening a report and sortin the rcords right. I an open the report, limited to a range of my choosing. So, for example the code below opens my report and limits it...
3
by: enough2Bdangerous | last post by:
access runtime error 3011 on docmd.openreport -------------------------------------------------------------------------------- Access database (file format 2002-2003) generates reports with...
4
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.