473,396 Members | 2,158 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,396 software developers and data experts.

open report with parameter

30
I am trying to pass the parameters when I open a report but the report opens with all records instead of being filtered.
Expand|Select|Wrap|Line Numbers
  1. Dim strReport As String
  2.     Dim strDateField As String
  3.     Dim startDate As String
  4.     Dim endDate As String
  5.     Dim strWhere As String
  6.     Dim lngView As Long
  7.     Const strcJetDate = "\#mm\/dd\/yyyy\#"
  8.  
  9.        strDateField=[SubmitDate]
  10.     Select Case Me!ReportToPrint
  11.  
  12.     Case 3
  13.             If IsNull(Forms![Reports Dialog]!SelectCategory) Then
  14.                 DoCmd.OpenReport "Category Reports", PrintMode
  15.             Else
  16.  
  17.      If SelectCategory.ListIndex = 0 Then
  18.         startDate = Date - 2
  19.         MsgBox startDate
  20.         endDate = Date
  21.  
  22.  
  23.     End If
  24.         MsgBox strDateField
  25.          strWhere = "(" & strDateField & " < " & Format(startDate, strcJetDate) & ")"
  26.         strWhere = strWhere & "(" & strDateField & " < " & endDate & ")"
  27.         Debug.Print strWhere
  28.         DoCmd.OpenReport "Category Reports", PrintMode, , strWhere
  29.             End If
  30.     End Select
  31.     DoCmd.Close acForm, "Reports Dialog"
Jun 15 '09 #1
6 4275
FishVal
2,653 Expert 2GB
Hello, xraive.

Your code is very messy.
  • startDate and endDate are declared as String type variables. However you assign Date type values to them. Though VBA could silently convert type to an appropriate one, the resulting value could be what you are not expecting for. To say nothing about that Format() function can't format String type value as Date type value.
  • Even though you've not attempted to format properly endDate variable value while incorporating it to strWhere.
  • There is no logical operator between two conditions in strWhere.
  • Having
    Debug.Print strWhere
    you might pay attention to the value of strWhere you try to pass to the report.
  • Just out of curiosity - what is the reason to name vaiables startDate and endDate this way. Do you think it is something about Hungarian notation?

Kind regards,
Fish.
Jun 15 '09 #2
NeoPa
32,556 Expert Mod 16PB
XRaive,

Please remember to use the CODE tags rather than the QUOTE tags for your code.

Also, it is courteous to indent your code properly before posting if you expect people to read through it. Messy code is no help to you, and is likely to irritate those you are hoping will help you.

If Fish's comments don't help you to your solution (I expect they will in fact) then I suggest you get clear which line of code is causing your problem (which of the two calls on lines #14 & #28) and then look through the Help documentation for the call (DoCmd.OpenReport()). You will find everything you need there to explain your problem.
Jun 15 '09 #3
xraive
30
I apologize for the messy code guys and for not using the code tags. I will in the future.

Thank you,
Jun 15 '09 #4
NeoPa
32,556 Expert Mod 16PB
Did you find that sorted your problem?

PS. Some (hopefully) helpful info on using the CODE tags (I meant to post before for you) :

Tags are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [ CODE ] tags has a hash (#) on it. You can choose which editor to use in your profile options (Look near the bottom of the page).
Jun 15 '09 #5
xraive
30
Thank you Neopa I will follow your instructions.

In regards to the problem I was having I decided to create hidden text fields that store date criteria on the form. I changed the query to refrence those two date fields on the form when running the report. This way I removed the need to store the date values in my code.

Thank you,

Rezene A.
Jun 15 '09 #6
NeoPa
32,556 Expert Mod 16PB
That sounds good. As long as your problem is behind you :)
Jun 15 '09 #7

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

Similar topics

3
by: CSDunn | last post by:
Hello, I have a situation with MS Access 2000 in which I need to display report data in spreadsheet orientation (much like a datasheet view for a form). If you think of the report in terms of what...
5
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
6
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a...
8
by: lauren quantrell | last post by:
When I open an Access form I can have no recordset specified, then in the form's OnOpen event I can do something like: Me.paramaters = "@SomeColumn = 22)" Me.recordsource = "dbo.sproc123" But I...
31
by: Randy Yates | last post by:
When I try fprintf(file, "Report of File %s\n", sMF->fileName); I get a core dump. This works fine if fprintf is changed to sprintf and a string buffer used instead as the first parameter. ...
0
by: Dean Sabella | last post by:
Hi, I was trying to run a crystal report in the .net sample application given at: http://support.crystaldecisions.com/communityCS/FilesAndUpdates/ cppnet_win_subreport_basic.exe.asp (I've...
0
by: Henry | last post by:
I have written an ASP/VB.Net application via VS 2003 (Crystal V9) that uses MS Access 2000 as its database. I can export reports that have no linked sub reports for printing. However, I'm unable...
3
by: mo | last post by:
I have an application that uses Reporting Services. When the user chooses to print a report, they are taken to a window that allows them to fill in parameters for the report. They then click a...
7
by: Steve_Black | last post by:
Hello, I'm toying with the idea of loading a MenuStrip (VB.Net 2005) dynamically based on who is logged into my system. Every user has different security settings and I want to customize the...
0
by: kamboj.shalabh | last post by:
Hi to all, Well, I am working on dotnet 2005 with crystal reports 10 and backend as sql server. I am facing a problem while loading a report. Actually the issue is, when I load report it takes...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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
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,...

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.