I am trying to design an indididual report card for the students of my college. I have a table called "tbl_student" where their marks are stored. I have 6 columns for 6 different subjects. A student can choose only 5 subjects i.e 4 being required and Computer and Maths are optional subjects where a student can choose either one.
Now, if a std chooses Comp. then marks in the maths column is 0, likewise for maths.
I am trying to print an individual report cards for 10 students. But one of the label for the optional should display Computer or Mathematics based on the value of the column.
Here is the code i tried
'declare the variables
Dim d As Database
Dim r As Recordset
Dim comp As Field, maths As Field
'the data from the table
Set d = CurrentDb()
Set r = d.OpenRecordset("tbl_student")
Set id = r.Fields("Student ID")
Set comp = r.Fields("Computer")
Set maths = r.Fields("Mathematics")
'check for the column value
While Not r.EOF
If (comp = 0) Then
Me.labelOptional.Caption = "Mathematics"
ElseIf (maths = 0) Then
Me.labelOptional.Caption = "Computer"
Else
Me.labelOptional.Caption = "none"
End If
The result is it captions all the labels the same for all students.
If you want to display different values for different rows in report/form, you should use bound text boxes. Labels and unbound text boxes will be the same for all rows in details section. Add new calculated column for optional label in base query and use it instead of label.
Related
I'm working with a data set to show customer margins (product) before & after freight costs.
I have just about everything working, but I am stumped on how to do freight correctly. My boss wants Freight to appear as a column rather than a row.
I have my dataset as such:
Customer # | CustomerName| FiscalYear | FiscalMonth | Itemcode | Revenue | Cogs | Freight | [RN]
In my report, my row group is CustomerNo
My column group is FiscalMonth (I'm doing a pivot with SSRS)
For Freight, I am using MAX(FREIGHT) since freight is the same for every item for a customer in a fiscal month. I used MAX since Distinct isn't an option in SSRS. This appears to be working for individual customers and fiscal month appropriately.
Where I am stuck, is how to get the SUM(MAX(FREIGHT)) for the fiscal month of all Customers (Grand Total) as well as the grand total for a customer for all fiscal months. For the grand total, I've tried several variations of =sum(Max(Fields!Freight.Value,"FiscalMonth"),"CustomerNo") or =sum(Max(Fields!Freight.Value,"CustomerNo"),"FiscalMonth") and keep getting errors like:
"The Value expression for the textrun ‘Textbox13.Paragraphs[0].TextRuns[0]’ has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a dataset."
"The Value expression for the text box Textbox uses both row and column scopes or scopes from two different data axes in the same aggregate expression. All nested aggregate functions must specify a named scope along the same data axis as the scope of the containing aggregate."
I've done some searching and keep trying to adjusting my expression but cannot seem to find the answer.
I had this same issue before and ended up writing a function to add the unique values. The data is sent as a single field with a Pipe | separating the values. It then checks to see if a customer is unique and adding the value if so.
FUNCTION SUMCustomers(BYVAL ITEMS AS OBJECT()) AS DECIMAL
'Returns Sum of unique Customers. Use as Code.SUMCustomers(Customer & "|" & Amount)
IF ITEMS IS NOTHING THEN
RETURN NOTHING
GOTO EXITSUB
END IF
DIM TEMP AS STRING
DIM Customers AS STRING = ""
DIM Customer AS STRING = ""
DIM VALUE AS DECIMAL
FOR EACH ITEM AS OBJECT IN ITEMS
TEMP = CONVERT.TOSTRING(ITEM)
Customer = "|" & LEFT(TEMP, InStr(TEMP, "|"))
VALUE = CDEC(MID(TEMP, InStr(TEMP, "|") + 1, LEN(TEMP)))
IF InStr(Customers, Customer) = 0 Then
Customers = Customers + Customer
SUMCustomers = SUMCustomers + VALUE
End If
NEXT
EXITSUB:
END FUNCTION
The expression for your issue would be something like
=Code.SUMCustomers(Fields!CustomerNo.Value & "|" & Fields!Freight.Value)
I am editing someone elses database who used the "set type" to store the data.
There is one row that stores all the "profile data" for the user and then in that row is multiple "sets" that have been selected by the user preferences as numbers.
Example of one row in database OLD:
profilevalue_id = 1
ProfileUser_id = 120
profilevalue10 = hockey
profilevalue50 = 2,4,5,6,19 (the set)
I need to copy this to a new database and 'expand' that set into individual items like
Example of one row in new database NEW:
item_id = 120
field_id = 10
value = hockey
Example of the set row in the new database NEW:
item_id = 120
field_id = 50
value = 2
The next number in the set as an individual row NEW:
item_id = 120
field_id = 50
value = 4
and so on... I've found information about break sets via string, but not what i'm looking for here... any advice on where to start looking?
Thank you.
Is there any way to apply another language to Access forms. I have an issue while creating forms, as the DB values are stored in English and I have to generate two identical forms from same Table in different languages. Everything goes well till I reach a look up field like Gender. My table optional values are 'Male' and 'Female' and is good for English form but How can I change that in my non-English form without changing table value
One way to do it would be to store the actual values in the main table as M and F, e.g.
ID FirstName Gender
-- --------- ------
1 Gord M
2 Angie F
and create a reference table named [Genders] like so:
TableValue Language Translation
---------- -------- -----------
M fr_ca masculin
F fr_ca féminin
M en_us Guy
F en_us Girl
M en_ca Male
F en_ca Female
On your form, create a hidden unbound text box named txtFormLanguage, and in the Form_Load event handler populate it like this:
Private Sub Form_Load()
Me.txtFormLanguage = IIf(IsNull(Me.OpenArgs), "en_ca", Me.OpenArgs)
End Sub
Now your combo box can use the following as its Row Source...
SELECT TableValue, Translation FROM Genders WHERE (((Genders.Language)=[txtFormLanguage]));
...and have other properties similar to the following:
Bound Column: 1
Column Count: 2
Column Widths: 0";1"
When the form is opened normally (without OpenArgs)...
Docmd.OpenForm "ClientForm", acNormal, , , acFormEdit, acWindowNormal
...it defaults to en_ca (English, Canada) and the combo box displays
Male
Female
When the form is opened for fr_ca (French, Canada)...
Docmd.OpenForm "ClientForm", acNormal, , , acFormEdit, acWindowNormal, "fr_ca"
...the combo box displays
masculin
féminin
I need to modify an existing report using SSRS 2008 with a Region name and it may contain 10 different regions. There is only one column set up for the region which may contain 10 different values. I believe it is a tablix. Currently, the regions are sorted in the code alphabetically but I have to sort them differently, so I assigned a number to each in the CASE statement based on the desired order. I then sorted the regions by the required order in the column itself (tablix) and the regions are sorted in the desired order in the report but unfortunately, the number assigned is in the report instead of the region name. Instead of getting
BF CF CO CL etc…. I get
1 2 3 4 etc in the heading of the report.
CASE ,
WHEN teamgroup.Name = 'BF' THEN 1
WHEN teamgroup.Name = 'CF' THEN 2
WHEN teamgroup.Name = 'CO' THEN 3
WHEN teamgroup.Name = 'CL' THEN 4
WHEN teamgroup.Name = 'CN' THEN 5
WHEN teamgroup.Name = 'GA' THEN 6
WHEN teamgroup.Name = 'IN' THEN 7
WHEN teamgroup.Name = 'KY' THEN 8
WHEN teamgroup.Name = 'MD' THEN 9
WHEN teamgroup.Name = 'NF' THEN 10
END AS Region
I tried to display teamgroup.name as region and then used Region_sort as the alias for the CASE statement, but it did not work. In the Tablix Properties, I used sort by: region_sort and order is A to Z but the regions were sorted alphabetically.
any help will be greatly appreciated.
You can sort the tablix in a different manner to what is being displayed.
You should setup the tablix as per normal with the region as the display values, this being the teamgroup.name.
Using the sort option on the tablix will oftern not work depending on the makeup of your table. The best and most reliable way is in the grouping properties window right click the details row and edit the sort by options.
Here you can edit the expression for the sort and I suggest you use a switch function to change the names to numbers, or better yet use the SQL region_Sort column if you have one.
Then set the order to a to z.
If you have groups in your tablix you will need to do this for the teamgroup.name region/group instead of the detail one.
In a database of Microsoft Access containing 500 employees of different categories I want only certain number of employees in each category. e.g., 2 employees of Category A, 5 employees of category B, 8 employees of category C.
Thus I want to create 10 separate groups wherein each person should be found in one list only, i.e. there should be no duplicate record. Each report should contain randomly selected unique record. One employee in one list should be found in another list.
Please help by clarifying how to achieve? I tried by creating union query. But, I got the result of duplicate records only. I also tried random limit expression but of no avail. Preferably the grouping should be based on the centre allotted.
The database looks as follows:-
Employee Name Category Duty As Centre allotted
1. XXXXX A I 1
2. XXXXX A I 1
3. XXXXX B II 1
4. XXXXX B II 1
5. XXXXX B II 1
6. XXXXX C III 1
7. XXXXX C III 1
8. XXXXX C III 1
9. XXXXX C III 1
How do I do this please?
Would something like this suit?
SELECT p.ID, p.EmpName, p.Category
FROM Persons P
WHERE p.ID In (
SELECT Top 2 ID
FROM Persons
WHERE Category = "A"
ORDER BY Rnd(ID)+ID)
OR p.ID In (
SELECT Top 5 ID
FROM Persons
WHERE Category = "B"
ORDER BY Rnd(ID)+ID)
OR p.ID In (
SELECT Top 8 ID
FROM Persons
WHERE Category = "C"
ORDER BY Rnd(ID)+ID)
ORDER BY p.Category
One approach to do this would be to add a field to the employees table called flag with a yes/no data type. Then create a form with the following controls on it:
Command button with a caption of reset flag to no for all records
A combo box that lists all the different categories
A text box to store the number of records to select
Another command button with a caption of flag records
Then the on the click event VBA code would look something like the following:
Private Sub cmdFlagRecords_Click()
Dim lngRandomNumber As Long
Dim k As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
strSQLText = "Select * From Employees Where Category='" & Me.cboCategory & "'"
Set rs = db.OpenRecordset(strSQLText, dbOpenSnapshot)
k = 0
Do Until k = CLng(Me.txtRecordsToSelect)
' generate a random number between one and the number of rows available
lngRandomNumber = CLng(Rnd(1) * rs.RecordCount)
'move to that record
rs.AbsolutePosition = lngRandomNumber
If Not rs![flag] Then
' set the flag to yes or true and increment the k variable
db.Execute "Update Employees Set=True Where ID=" & rs![ID]
k = k + 1
End If
Loop
rs.Close
End Sub
You can then click the button as many times as necessary to build up your selection.