MS Access, modifying combobox data type - ms-access

Fairly new to MS Access (been at it for about 6 or 7 months and pretty much self taught, I bow at the alter of Google and Stackoverflow a lot) and am working on a form for a database that is to allow the user to create reports and dictate what they want in the report.
How it's set up is the user has one list that's pre-populated and doesn't change where they select whether the report will show projects that happened during a certain fiscal period, non-project related trips (we'll call them NPTs for now) that happened during a certain fiscal period, or a certain project series.
The second list (also prepopulated and unchangeable) only activates if the first or second item in the first list are selected. It allows the user to select the fiscal period and gives the options of either: fiscal year, fiscal quarter, month, or year-on-year comparison.
Once an item in both of those lists are selected it populates the list of one or two comboboxes with options based on what's available in the table that it's pulling from.
The first combobox will always be populated and visible, what it's populated with alters. If the fiscal year, fiscal quarter, month or year-on-year options are selected the first combobox will be populated with the available fiscal years, and if the project series option is selected then it's populated with a list of series names.
There is a second combobox but it isn't relevant to my question so I'll leave details about it out.
My problem comes from the first combobox. Now when you open a new instance of the form no data type is assigned to the combobox but let's say that a user wants to create a report by projects in a fiscal year and he/she selects a fiscal year in the combobox then changes their mind and decides to do a report by project series. When you go to try and select a project series name in the combobox that was populated with fiscal years earlier an error message pops up stating that you're trying to input text into a numeric data type field.
So my question is, is there a way to programmatically change the allowed data type for the first combobox in the AfterUpdate Sub of the first list?
Here's an example of what I have for the first list AfterUpdate Sub (RptByType is the first list):
Me.combobox1.RowSource = Switch(RptByType = Project, _
"SELECT DISTINCT Proj.FiscYr FROM Proj ORDER BY Proj.FiscYr DESC;", _
RptByType = Trips, "SELECT DISTINCT NPT.FiscYr FROM NPT ORDER BY NPT.FiscYr DESC;", _
RptByType = Projseries, "SELECT DISTINCT Proj.SeriesNm FROM Proj;")
And again FiscYr is in an Integer format, while SeriesNm is in a String format, also combobox1 is not a bound field

Related

SSRS group by multiple fields and groupings

I have a query that returns the following fields:
GrantCode
EmplID
EmployeeFullName
AssignedUnit
DaysOff
HourlyRate
CalendarEventStart
CalendarEventEnd
NumberOfHours
StatuteNumber
ViolationDescription
I want to have a stepped SSRS report that shows:
the calendar start time, end time and number of hours under the employee name info and then another grouping that shows the citations that were issued during the time period. I can't quite figure out how to get the SSRS groups set up to display in this manner.
I currently have all the data in a single query/data set but can separate it if that will make the reporting easier.
Any suggestions?
Thanks!
Leslie
Add a tablix to your report. Put in the tablix the fields Citation Number, Statue Number, Violation Description, Number of Citations. Then go to Row Groups > Add Group > Parent Group chose for group by the EmplID and check the Add group header, then hit OK.
Afterwards click on the most left column in your tablix and chose Insert Column > Inside Group - Right. Do this a few times and put in these colums the fields EmployeeFullName, Assigned Unit, HourlyRate, DaysOff, StartTime, EndTime.
Then go to your Row Groups and click on the drop down by (Details) and chose Group Properties > Visibilty and check Display can be toggled by this report item:. Here you have to chose the name of the textbox where the EmplID field is. Now the detail data get toggled by the EmplID.
If you want other data to display just add another column and put your fields or expressions in this column. A new column before the two dotted lines is on the group level and column after the two dotted lines are for the detail section.

Filter data set by month

I'm using an embedded data source of type SharePoint List.
I use a parameter that a user can modify that will filter the data set by the month. I've seen a few examples but they all either use a SQL query or only filters on the exact day rather than the month.
I added a parameter ParamMonth and gave it the data type of Date/Time. I can see this adds a drop down box to my report which is exactly what I want. Ideally, I would like to add the name of all 12 months or something similar, but I don't know how that will work out when the data exceeds a single year. Now, that I've got my Report Parameter added, I need to add it to my dataset to filter on. This is where I'm stuck.
An easy way could be creating a parameter type Integer and set all months in Available Values tab as follows (I just set five months for example).
Then go to the DataSet Properties / Filter tab and use the below settings.
For expression use:
=MONTH(Fields!Date.Value)
Where Date is the field that you will use to filter by month. In Value you have to use:
=Parameters!Month.Value
UPDATE: Provide year selection.
The best approach for this is getting the available values from a DataSet, in this case your SP list.
Just create a calculated field in your dataset with available years (it can be a copy of the SP list dataset), call it calculatedYear and use:
=YEAR(Fields!Date.Value)
Now create a Year parameter of Intenger data type, and set this settings:
Where DataSet15 is the DataSet name that feeds your parameter with the available years.
Then just add another filter in your dataset:
Note you will need two datasets one to get the available years and
other the dataset you need to filter.
Let me know if this helps.

How to allow dayname in input string when inputting a date?

In our continuous form in Access we want to offer a combobox which will show 7 days with the dayname as part of the dropdown.
The combobox is bound to a date field. We can easily populate the combobox in the Form Load event to show the days in ddd dd/MM/yy format and existing dates are happily shown on the form like so:
However if you try and pick from the dropdown you get the error:
The value you entered isn't valid for this field.
Solutions involving an unbound combobox won't work as this is a continuous form.
It's kind of a detail, as the dayname isn't absolutely necessary, and the combo works fine without the dayname. However this is a heavy duty data entry form so optimising for the end user is important and having the daynames will assist him/her.
I recreated the problem and the solution I came up with was to have a combo box where the row source has two columns and you hide the first column using ColumnWidths and the second column is the formatted date value. So when you pick something in the combo box, the value is an unformulated date value which gives no issue.
Populate the combo like so:
Dim i As Integer
For i = 0 To 6
Dim item As Date
item = DateAdd("d", i, weekCommencingDate)
cboTimeDate.AddItem item & ";" & Format(item, "ddd dd/MM/yy")
Next i

How to Reference Individual Form Elements in a MS Access Continuous Form

MS Access Scenario:
I am using a form (we'll call it the select_contract form) and a subform (we'll call it the employee_allocations_by_contract subform).
The select_contract form:
Is unbound.
Contains a combobox that allows the user to select a contract id.
The employee_allocations_by_contract subform:
Is a continuous form.
Is bound to a table (which I'll call the hours_allocation table) that contains the number of hours that each employee is allocated to each contract.
Binds only one field, the employee_id field, to the hours_allocation table. The row source for this field is a query that returns the ids of employees that have hours allocated to the contract that the user has selected in the select_contract form.
Contains twelve other, unbound fields, one for each month of the year. These fields are intended to display the number of hours allocated to the employee listed in the employee_id field for each month of the year.
The Problem: In order to display the number of hours by month that are allocated to each employee listed on the employee_allocations_by_contract subform, the queries for each month field need access to the employee_id field of the row on which they appear. I haven't been able to figure out how to reference this field. Because the employee_allocations_by_contract subform is a continuous form, a reference to the the employee_id field name appears to reference each row on the form.
I have searched several forums and have found related continuous form issues, but nothing that clearly addresses this problem. Any thoughts?
Well, you could build a sub-query for each of the month columns you need that total for.
Something like:
Select id, employee_ID, bla, bla, bla,
(select sum(hours) where month = 1 and year = 2010 and
employee_id = ehours.Employee_id from tblProjectHours)
as month1,
(select sum(hours) where month = 2 and year = 2010 and
employee_id = ehours.Employee_id from tblProjectHours)
as month2,
(select sum(hours) where month = 3 and year = 2010 and
employee_id = ehours.Employee_id from tblProjectHours)
as month3
etc. for each column needed
from ehours
Note I used month and year as columns and you likely have to use month([SomeDate]) = 2 and year([SomeDate]) = 2010, but you get the idea.
Also, while you can't address each row and stuff a value into that un-bound text box, you CAN in fact bind the text box to a function that returns the value/expression you need.
txtBoxMonth1 txtboxMonth2 etc.
=MyMonth(1,[employee_id]) =MyMonth(2,[Employee_id])
And, then in the form, you have a public function called
Public Function MyMonth(intMonth as interger, lngEMPID as long) as long
' code here to get total based on employee id and month
End Funciton
So, you can bind a function to those text boxes, and the current row emp ID can thus drive what each text box displays. Just remember that this function should have all of the data pre-processed, and you don't want to have to re-run and re-load the data for each function call as that will be FAR too slow. However, I have used this approach to much success. So, each row of the form only has one real column (empID), the rest of the columns are derived from text boxes bound to the public function as per above with the month being passed along with the emp id to return the value for that column.
So, above is two possible approaches I used with success.
An unbound control on a continuous form can only refer to the record that has the focus. There fore, if data is entered into an unbound control, you will see the same data for every record in the continuous form.
You cannot reference controls "individually" ("at the line level") in a MS Access continuous form.
Your only solution here is to bound these controls to an underlying recordset\recordsource where corresponding fields hold the values to be displayed.
For example, if you want to display a time period as the difference between a "date in" and a "date out", your recordset\recorsource could be something like:
select id_person,dateIn,dateOut,dateDiff(xx,dateOut, dateIn) as timeIn from ...
Then your time calculation control has to be bound to the 'timeIn' field of the recordset.
(*) please check the dateDiff arguments. I do not have any help available here ..

SQL Reporting

I have a chart report that displaying monthly data and i want to display previous and next month data by clicking previous and next month.
How to display data in chart by clicking previous and next month.
Add a parameter to the report to specify the month. Create two text items in the RDL for this report for previous and next. Configure the 'jump to' item for these two tems to invoke this same report with correct value for the month deduced from the month value in the current report. It will be month - 1 for prev and month + 1 for next. In short, you will be calling the same report for both the prev, next and for the current month.
not sure what environment you are in, but you could use the following SQL to get you the next/previous months (using oracle). Use this as your starting point for building your query.
next button: select to_char(sysdate,'MM')+1 from dual
previous button: select to_char(sysdate,'MM')11 from dual
Once you get your requested month, build the remaining resultset.