473,750 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date Range on a report??

smithj14
18 New Member
I have a form to enter start and end dates then select a worker name to filter a report. This all works fine and when the report is open in preview mode it shows the date range in the txtboxes on the report header, but when I print the report the value for these txtboxes are #Name?

Here is the code
Date Range Form:

Private Sub cmdViewErrorRep ort_Click()
Dim stDocName As String
Dim stDocName2 As String
Dim stWhere As String
Dim stLinkCriteria As String
Dim lngLen As Long

stDocName = "Error Report"
stDocName2 = "Error Report - Date Range"
stLinkCriteria = " [ReviewDate] Between " & CLng(Nz(Me.txtB eginDate, txtEndDate)) & " And " & CLng(Me.txtEndD ate)

Me.Filter = stLinkCriteria
Me.FilterOn = Len(stLinkCrite ria)

If Not IsNull(Me.cboWo rker) Then
stWhere = stWhere & "([Worker] = """ & Me.cboWorker & """)"
DoCmd.OpenRepor t stDocName, acViewPreview, stLinkCriteria, stWhere
End If

DoCmd.Close acForm, stDocName2
DoCmd.RunMacro "PrintErrorRepo rt"
DoCmd.Close acReport, "Error Report"
End Sub


The controlsource property of the txtboxes on my report:

txtBeginDate:
=Forms.[Error Report - Date Range].txtBeginDate

txtEndDate:
=Forms.[Error Report - Date Range].txtEndDate

I know the code isn't pretty, I am still testing and have not added error checking yet but all is working except this part.

The only thing I haven't tried is changing the name of the report. Maybe the spaces and dash need to removed?

Help
Oct 6 '08 #1
12 3271
nico5038
3,080 Recognized Expert Specialist
Normally I use a form to enter the date(s) and/or additional fields and pass these as the filter parameter when starting the report.
Another option is to have the parameters in the WHERE clause like e.g.
[Begin date: ]
as this will ask for a value when the report is started.

Finally when you have the fields on a report (which effectively should be "output only"), the you would have to refer to:
=Reports.[Error Report - Date Range].txtEndDate

But I wouldn't use input textfields on a report, but on a form...

Nic;o)
Oct 6 '08 #2
smithj14
18 New Member
Sorry, I might have not been clear enough. The code I posted was from the click event from a seperate unbound form that has txtboxes to enter dates and a combobox to select the worker then filter the report based on these criteria.

Then the report auto prints and closes displaying all the correctly filtered data on the printed report.

I just need the entered date values from the form to print out on the report.
The txtboxes on the report are not used for input just to display the date values.

If you need more info let me know.
Oct 7 '08 #3
nico5038
3,080 Recognized Expert Specialist
Strange, as it should work as you code the fields.
Perhaps the formname with the embedded "-" sign causes trouble as some Access versions aren't "happy" with special characters in form and/or field names.

Can you retry this with a form just named like "frmReportStart End".

Nic;o)
Oct 7 '08 #4
youmike
69 New Member
Nico's advice regarding embedding "-" is good. Access just doesn't like that sort of thing and you get most reliable (and fastest) performance if all object names are restricted to using A-Z (upper and lower case) and 1-9. Using a capital at the start of each word in the name as Nico suggests makes names easier to read.

I'd also be inclined to redesign stWhere so that it doesn't have successive double quotes. I tend to favour passing values of controls to global constants, which in this case would be set via the after update event of the combo box. In this case, you'd declare a string constant, say gcstrWorkerName . I use the prefix gcstr for a global string, because it is helpful when debugging. I also tend to put all such global declarations in a VBA module which I call modConstants.

If you adopt this approach, your code to build stWhere (which would need to be declared as global) would look something like
If Not IsNull(Me.cboWo rker) Then
gcstWhere = stWhere & " AND Worker = " & gcstrWorkerName
End if.

Hope this makes sense
Oct 7 '08 #5
smithj14
18 New Member
Ok, thank both of you for the point in the right direction.
I now have it working printing the date range on the report. I created a new form and used a different approach to the coding. The code I was using would only work if both dates were entered. Now I can enter a start date, an end date or both, and all works fine. I think my problem was with the selection of the worker. When I added that part of code it did not work again, so I removed it.

Here is the code I used:

Private Sub cmdErrorReport_ Click()
Dim stReport As String
Dim stForm As String
Dim stMacro As String
Dim stDateField As String
Dim stWhere As String
Dim lngView As Long
Const stDateFormat = "\#mm\/dd\/yyyy\#"

stReport = "ErrorRepor t"
stForm = "ErrorDateRange "
stMacro = "PrintErrorRepo rt"
stDateField = "[ReviewDate]"
lngView = acViewPreview

If IsDate(Me.txtSt artDate) Then
stWhere = "(" & stDateField & " >= " & Format(Me.txtSt artDate, stDateFormat) & ")"
End If

If IsDate(Me.txtEn dDate) Then
If stWhere <> vbNullString Then
stWhere = stWhere & " AND "
End If
stWhere = stWhere & "(" & stDateField & " < " & Format(Me.txtEn dDate + 1, stDateFormat) & ")"
End If

If CurrentProject. AllReports(stRe port).IsLoaded Then
DoCmd.Close acReport, stReport
End If

DoCmd.OpenRepor t stReport, lngView, , stWhere

DoCmd.RunMacro stMacro
DoCmd.Close acForm, stForm
DoCmd.Close acReport, stReport

End Sub

However i still need to select a worker name from a combo box and have the report filter by the entered dates and the worker name. This part is a must as we view the report based on the workers errors and needs to be specific to each worker.

Can you guys help with this or should I start another post with that part of problem?
Oct 7 '08 #6
nico5038
3,080 Recognized Expert Specialist
You'll need to code all combinations of dates and worker filled and/or empty.
Would look something like:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdErrorReport_Click()
  2.  
  3. Dim stWhere As String
  4.  
  5. stWhere = ""
  6.  
  7. If IsDate(Me.txtStartDate) and IsDate(Me.txtEndDate) Then
  8.    stWhere = "([ReviewDate] between #" & Format(Me.txtStartDate, "mm-dd-yyyy") & "and & Format(Me.txtEndDate, "mm-dd-yyyy") & ")"
  9. elseif IsDate(Me.txtStartDate) then
  10.    stWhere = "([ReviewDate] >=" & Format(Me.txtStartDate, "mm-dd-yyyy") & ")"
  11. elseif IsDate(Me.txtEndDate) then
  12.    stWhere = "([ReviewDate] <=" & Format(Me.txtEndDate, "mm-dd-yyyy") & ")"
  13. End If
  14.  
  15. ' stWhere filled?
  16. IF len(stWhere) > 0 then
  17.    if len(nz(Me.cmbWorker)) > 0 then
  18.       ' cmbWorker filled and stWhere
  19.       stWhere = stWhere & " AND ([Worker] =" & Me.cmbWorker & ")"
  20.    endif
  21. else
  22.    if len(nz(Me.cmbWorker)) > 0 then
  23.       ' cmbWorker filled and stWhere empty
  24.       stWhere = "([Worker] =" & Me.cmbWorker & ")"
  25.    endif
  26. endif
  27.  
  28. If stWhere <> "" Then
  29.    DoCmd.OpenReport "ErrorReport", acViewPreview, , stWhere
  30. else
  31.    DoCmd.OpenReport "ErrorReport", acViewPreview
  32. endif
  33.  
  34. End Sub
  35.  
Just keep the form opened, thus an erroneous selection can be corrected easily by the user.

Nic;o)
Oct 7 '08 #7
smithj14
18 New Member
I am getting there, slowly but surely.

I used some of the code you suggested and added some of my variables.

It filters the report by the worker now. When I enter a date range and select a worker I get the following runtime error:

Run Time Error '3075':
Syntax error (Missing Operator) in query expression '((stDateField between ##09/01/2008# and #09/30/2008#) AND [Worker] = 'Last, First')'

When I enter just a date range and no worker I get the following runtime error:

Run Time Error '3075':
Syntax error (Missing Operator) in query expression '((stDateField between ##09/01/2008# and #09/30/2008#))'

I have the worker names stored in this format:
Column - WorkerName
Date - LastName, FirstName


Here is my code:

Private Sub cmdErrorReport_ Click()
Dim stReport As String
Dim stForm As String
Dim stMacro As String
Dim stDateField As String
Dim stWhere As String
Dim stLinkCriteria As String
Dim lngView As Long
Const stDateFormat = "\#mm\/dd\/yyyy\#"

stReport = "ErrorRepor t"
stForm = "ErrorDateRange "
stMacro = "PrintErrorRepo rt"
stDateField = "[ReviewDate]"
lngView = acViewPreview



If CurrentProject. AllReports(stRe port).IsLoaded Then
DoCmd.Close acReport, stReport
End If

stWhere = ""

If IsDate(Me.txtSt artDate) And IsDate(Me.txtEn dDate) Then
stWhere = "(stDateFie ld between #" & Format(Me.txtSt artDate, stDateFormat) & " and " & Format(Me.txtEn dDate, stDateFormat) & ")"
ElseIf IsDate(Me.txtSt artDate) Then
stWhere = "(stDateFie ld >=" & Format(Me.txtSt artDate, stDateFormat) & ")"
ElseIf IsDate(Me.txtEn dDate) Then
stWhere = "(stDateFie ld <=" & Format(Me.txtEn dDate, stDateFormat) & ")"
End If

If Len(stWhere) > 0 Then
If Len(Nz(Me.cboWo rkerName)) > 0 Then
stWhere = stWhere & " AND [WORKER] =" & "'" & Me.cboWorkerNam e & "'"
End If
Else
If Len(Nz(Me.cboWo rkerName)) > 0 Then
stWhere = "[Worker]=" & "'" & Me.cboWorkerNam e & "'"
End If
End If

If stWhere <> "" Then
DoCmd.OpenRepor t stReport, lngView, , stWhere
'DoCmd.RunMacro stMacro
'DoCmd.Close acForm, stForm
'DoCmd.Close acReport, stReport
Else
MsgBox "You must enter a worker and date range for this report!", vbOKOnly, "Not enough information!"
End If
End Sub


Thank you in advance. Especially if it is a dumb mistake on my part.
Oct 8 '08 #8
nico5038
3,080 Recognized Expert Specialist
There's an additional "#" before the first date, remove it from the stWhere filling.

Nic;o)
Oct 8 '08 #9
smithj14
18 New Member
Ok I just about have it.

If I enter just start date, I get reports from then on.
If I enter just end date, I get reports from then back.
If I select just worker name, I get reports for that worker.

Only problem is they don't all work together. If I enter a worker and the wrong date range the report still opens with all fields saying error.

Here is the latest code:

Private Sub cmdErrorReport_ Click()





Dim stReport As String
Dim stForm As String
Dim stMacro As String
Dim stDateField As String
Dim stWhere As String
Dim stLinkCriteria As String
Dim lngView As Long
Const stDateFormat = "\#mm\/dd\/yyyy\#"

stReport = "ErrorRepor t"
stForm = "ErrorDateRange "
stMacro = "PrintErrorRepo rt"
stDateField = "[tblQALog].[ReviewDate]"
lngView = acViewPreview



If CurrentProject. AllReports(stRe port).IsLoaded Then
DoCmd.Close acReport, stReport
End If

stWhere = ""

If IsDate(Me.txtSt artDate) Then
stWhere = "([tblQALog].[ReviewDate] >=" & Format(Me.txtSt artDate, stDateFormat) & ")"
ElseIf IsDate(Me.txtEn dDate) Then
stWhere = "([tblQALog].[ReviewDate] <=" & Format(Me.txtEn dDate, stDateFormat) & ")"
End If

If Len(stWhere) > 0 Then
If Len(Nz(Me.cboWo rkerName)) > 0 Then
stWhere = stWhere & " AND [WORKER] =" & "'" & Me.cboWorkerNam e & "'"
End If
Else
If Len(Nz(Me.cboWo rkerName)) > 0 Then
stWhere = "[Worker]=" & "'" & Me.cboWorkerNam e & "'"
End If
End If

If stWhere <> "" Then
DoCmd.OpenRepor t stReport, lngView, , stWhere
'DoCmd.RunMacro stMacro
'DoCmd.Close acForm, stForm
'DoCmd.Close acReport, stReport
Else
MsgBox "You must enter a worker and date range for this report!", vbOKOnly, "Not enough information!"
End If

End Sub
Oct 9 '08 #10

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

Similar topics

7
1860
by: Garyrek | last post by:
Hi I have a requirement where I need to make a report for each auto dealer how many hits they got on specified date range, so for each car detail page I increment the counter and total it while doing that I store the last hit date, this gives the total hits for the dealer BUT does not facilitate date range How do I give the user a date range so that he can check how many hits the dealer got lets say for last week OR last couple of days? ...
5
4497
by: Michelle | last post by:
Hi all I have a report which displays staff absences. An absence record has a start and end date and the type of absence, ie sickness, annual leave. I have created a form which allows the user to specify criteria for viewing the report. The one I am having problems with is the date. I allow the user to set a date range, so for example, the user selects 01/03/04 to 08/03/04 and I want to be able to show all absences that
3
7465
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The report prints dental and hygenist appointments for the date (one subreport for each). The user wants to enter a date range and have one page for each date in the date range. I'm wondering how to modify the report. The only way I see is to create...
2
3847
by: Sara | last post by:
I have followed instructions on the http://allenbrowne.com/tips.html for limiting a report to a date range. At the bottom there is a note that says You will end up using this form for all sorts of reports. You may add an option group or list box that selects which report you want printed, and a check box that determines whether the report should be opened in preview mode. I have tried several times to do this but can't figure it out....
1
3977
by: irfanali | last post by:
Hallo All, This is a Tool i m tryin to develop at work. I will explain how it works and then the Q I download a report from my ERP Tool on a daily basis and upload it into the Access Tool. This report gives me the accounting bookings made on a daily basis. So it has fields like Invoice Nr, Invoice Amount, and Date. Well, then i have a Duplicate Query set up to give me a report for all Duplicates...and then i download it into an...
19
3926
by: ali3n8 | last post by:
Hello I have attempted to create a date range report from a query called qrycustomerinformation. The field that contains the value of my date is called Followup. When i run a report on this it is fine. But I have decided I would like to pull this report for a specific date range. Ive attempted to use the method on allen brownes page http://allenbrowne.com/casu-08.html. I would like to also mention the followup field also uses this code to...
7
2848
by: dozingquinn | last post by:
Hello, Is there any way to auto populate the user defined date range into a report? I currently have the criteria "Between And " for a date range field. This prompts the user to enter a date range before the report is visible. Is it possible to capture this date range and display it on the report? I am using Access 97 Thanks!
5
5415
by: jambonjamasb | last post by:
I am wanting to create a report that summarises the number of items within a date range. For example I have a FIELD called System_Change. This is a drop down COMBOBOX that uses words like unix, polfs etc. I know how to query a date range, but not how to count number of fields within this date range. I would like the report to show date range filtered then list all changes and number of times they appear. Thanks in advance anything...
9
1726
by: Mo | last post by:
After a little PHP education, my first project (to get my feet wet) is making an employee time-tracking program for our small business. *** ANY SUGGESTION, THOUGHTS, OR ADVICE WOULD BE WARMLY WELCOMED *** I'm in my planning stage, and here's my hurdle: On the time report, we want to see EVERY date under each employee, and the string "Absent" for the dates on which the user has no punch times. (It would also be nice to include day-names...
0
8839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9345
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8265
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6811
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2227
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.