I have a report where the user enters a FROM and TO date. What I'm trying to do is allow the user to view the inventory of the last day of the previous month. So lets take for example: user enters 12/7/2015, I want to be able to show the beginning inventory between 1/1/2000 and the last day of this dates (12/7/2015) which would be 11/30. I'm running this in VB6 just to make sure the number are correct. I've seen other answers on SO but for some reason I'm getting different results.
I try to run this but get a weird date...
?DateSerial(Year(12/1/2015),Month(12/1/2015),0)
Thsi gives me the following results...
11/30/1899
So the date seems to be okay, but the year is way off. Why?
Use Date:
DateSerial(Year(Date()),Month(Date()),0)
or, for a specific month:
DateSerial(Year(#12/1/2015#),Month(#12/1/2015#),0)
Related
I have a confirmation letter used to display one of two dates to a customer.
Date.Value is the purchase date of a product not tied to a finite inventory.
InventoryDate.Value is the date an activity is taking place, based on inventory availability.
Everything has a purchase date, but not everything has an inventory date. I would like the letter to display InventoryDate.Value if it has one, or display Date.Value if inventory date is null. I've played around with a bunch of variations in my code, but what I currently have is:
=iif( Fields!InventoryDate.Value="", Fields!Date.Value, Fields!InventoryDate.Value)
This is displaying Date.Value correctly, but returning #Error for any product with an Inventory Date. I am very new to SSRS/Reporting, so please keep any suggestions at a newb understanding level.
Working in MS Report Builder.
Thanks for your suggestions!
Depending on the data type of the fields, they can be blank or empty. With ="" you are only checking, if the field is blank.
try this:
=iif(IsNothing(Fields!InventoryDate.Value),Fields!Date.Value,Fields!InventoryDate.Value)
I am a beginner in using Access. In the past I used a database where I could select a beginning and ending date on a calendar, and the query would bring back all items that would "occur" during those dates. I would like to replicate that database.
The records would need to be pulled based on their frequency- for example I have items that occur on a monthly (on a certain date), weekly (on a certain day), bi-weekly (every other day of the week). (There are codes to represent this- for example PPBR would be every other Thursday; PPM23 would be the 23rd of each month; PPWT would be weekly every Tuesday). Like setting up a reoccurring appointment in outlook, these items would also continue for future dates so that I know when they need to occur next by just clicking on the calendar.
For example, on Tuesday June 23rd, all items that occur every other Tuesday, items for the 23rd and weekly on Tuesday should all be pulled into one report.
I have created a table for the main record info. I have also created a separate table listing all the variations of the frequency (code and day of week/date they occur) and have linked them.
I am stuck at this point as to how to create and incorporate the calendar function and would appreciate any assistance.
Thank you!
June7's comments direct you to ask a more focused question. I gather that you are simply asking how to incorporate "calendar functionality", but your detailed description muddles your intention.
Since you've create something like this before, I presume that the "calendar" you mean is simply the calendar-style date picker already available with the TextBox controls. In that case, you could add two unbound TextBox controls --one for the beginning date and one for the ending date-- and set the following properties in the Property Sheet:
Format: Short Date
Show Date Picker: for dates
After Update: [Event Procedure]
With the Show Date Picker property enabled, upon clicking inside the TextBox control a little Calendar icon is displayed. Clicking on that icon shows a pop-up date picker.
In the TextBox_AFterUpdate event handlers add code to update the Form's RecordSource with an appropriate query. (It would also be possible to refer to the TextBox values directly in a query, but your description of the date criteria sounds too complicated to handle in a single query directly.)
I have searched looking for help but can't find exactly what I need.
I am trying to find the total number of days between two date fields, however the initiating date fields could be from two different fields, eg Start Date, or amended Start Date. The end date will always be the same field.
The majority of the time there will not be an amended start date but I need a way to cater for the scenario that an start date has been amended.
I tried the following
=IIF(Fields!AmendedStartDate.Value is nothing, DateDiff("d",Fields!StartDate.Value,Fields!EndDate.Value, DateDiff("d",Fields!AmendedStartDate.Value, Fields!EndDate.Value)))
I get an error run a run this.
I am fairly new to Report Builder/SSRS so I am unsure if what I am asking for is even possible.
Thanks for taking the time to look.
You can't do Fields!FieldName.Value is nothing, instead you need IsNothing(Fields!FieldName.Value):
=IIf(IsNothing(Fields!AmendedStartDate.Value),DateDiff("d",Fields!StartDate.Value,Fields!EndDate.Value),DateDiff("d",Fields!AmendedStartDate.Value,Fields!EndDate.Value))
Alternatively, you could create a Calculated Field (called say, StartDateToUse) with a similar expression:
=IIf(IsNothing(Fields!AmendedStartDate.Value),Fields!StartDate.Value,Fields!AmendedStartDate.Value)
And then refer to this field in your main expression to get the result you want:
=DateDiff("d",Fields!StartDateToUse.Value,Fields!EndDate.Value)
I have a Report, I hope that if you choose to end time more than 7 days of the start time is prompt error.
Rather than give your users two date parameters have a single parameter to select the reporting period. You can use a SQL query to generate a list of weeks and then allow them to select which week they want to see data for. That way they can't ever select more than 7 days.
Otherwise you can short circuit the SQL by adding a DATEDIFF() between the two parameters. You could use an IF statement for this but you'll need to ensure that it returns the same columns and data types or I think SSRS will error out.
Otherwise just add the DATEDIFF() check in the WHERE clause so it will return no rows if the parameters are too far apart.
You'll also want to create a textbox on the report and have it conditionally visible if the parameters are too far apart. Something like big red text explaining to the user that they have selected a date range that is too large.
But, I think showing error messages should be avoided when you can just adjust the choices offered to the user so that they can't choose something that is invalid.
I've looked on a couple different forums and I'm unable to find what I need they all have it listed in SQL View, and that is NOT what I want. I would like to do this in the Query Design as it is much easier for me.
I simply would like to make a query to display certain parameters of the database I maintain. And those parameters would equal last month's data.
I previously was able to successfully make a query displaying all information for the past year but can't figure out how to display just this past months.
The past year Criteria:
>DateAdd("yyyy",-1,Date())
Since that worked I tried doing this but it would not work for me:
>DateAdd("mmmm",-1,Date())
I'm sure it's something simple that I'm just not seeing here. Any help or recommendations are welcome.
Referencing the link provided by Fionnuala I have come up with
>DateAdd("m',-30,Date())
The problem being is that it queries all results for the past 30 days from Today's date. I wish to display only data from October ! While this can be done easily. I don't wish to manually go in this query every month and change certain parameters. I would like it to be automatic so or next month December I click on the query and it displays all 30 days of November's data. And there is no manual process of going back in and changing any of the criteria.
In the Query Designer you can use a Criteria: like this
>=DateSerial(Year(Date()),Month(Date())-1,1) And <DateSerial(Year(Date()),Month(Date()),1)
The corresponding SQL statement is
SELECT Donations.*
FROM Donations
WHERE (((Donations.DonationDate)>=DateSerial(Year(Date()),Month(Date())-1,1)
And (Donations.DonationDate)<DateSerial(Year(Date()),Month(Date()),1)));
If it was run on November 18, 2014 then it would effectively be
SELECT Donations.*
FROM Donations
WHERE (((Donations.DonationDate)>=DateSerial(2014,10,1)
And (Donations.DonationDate)<DateSerial(2014,11,1)));
Notes:
This query should be sargable and take advantage of an index on the date field (if one exists).
In case anyone is concerned about "month wrap-around", the DateSerial() function takes care of that for us. If the query was run in January 2015 then the first WHERE condition would indeed be ... >=DateSerial(2015,0,1) but that's okay because it returns 2014-12-01.