What I want to accomplish:
1.Set the CaseNo column to for a new group to stand out in a separate line and same to follow for each detail until a new group is recorded.
2.Call the name of the column in a group total for that particular group
Currently, what I have produced is a bit different form the image below.
I have got the fix!
= "Total Gap for " & Fields!CaseNo.Value & " = " & Sum(Fields!Gap.Value)
Related
I want to use the result of a crosstab with a flexible amount of column headings in a form. The query shows how many hours employees (column headings) spent on different tasks (row headings).
The query works if I open it as is. Pulling it into the form I get the error message that I cannot use a crosstab query without fixed column headings. I need the ability to show a flexible amount of column headings since otherwise the resulting table is too big and confusing. Is there a solution for this problem?
That's the query:
PARAMETERS [Forms]![PL_Stundenabfrage]![ProjektWaehler] Long;
TRANSFORM Round(Sum(DateDiff("n",[tblZeiten].[ZE_Start],[tblZeiten].[ZE_Ende])/60),2) AS Stunden
SELECT [KS_Bez] & " (" & [KS_BezLang] & ")" AS Taetigkeit, Sum(Stunden) AS GESAMT
FROM tblMa INNER JOIN (tblKst INNER JOIN (tblPr INNER JOIN tblZeiten ON tblPr.PR_Key = tblZeiten.ZE_Pr) ON tblKst.KS_Key = tblZeiten.ZE_Kst) ON tblMa.MA_ISN = tblZeiten.ZE_MA
WHERE (((tblZeiten.ZE_Pr)=[Forms]![PL_Stundenabfrage]![ProjektWaehler]))
GROUP BY [KS_Bez] & " (" & [KS_BezLang] & ")"
PIVOT tblMa.MA_Nachname;
I have a form which is used to submit entries to a Table.
The ‘Monthly Adjustment $’ Field currently posts new table entries which works fine.
I would like to display the total balance from the Raw Data Table in the ‘Current Balance $’ field filtered based on the Company and Accrual ID that is selected by the user in the Form.
Each time the user selects a new Company and Accrual ID combination in the Form I want the ‘Current Balance $’ field to display the total $ for that Company and Accrual combination from the Raw Data Table.
To start with I have tried using a DSUM in expression builder to sum the ‘Amount $’ field in the Raw Data table, where the Accrual ID is equal to whatever value the user has selected in the Form’s ‘Accrual ID’ field. The next step would be to then add a second filter for the company selected (which I will do once I figure this first bit out). I have included the expression I am using below.
=Nz(DSum("[Amount $]","Accruals Raw Data","[Accruals Raw Data]![Accrual ID]= ' " & [Forms]![Single Accrual Entry - Form]![Accrual ID] & " ' "))
However when I select an option in the Accrual ID field in the form it does not return any results in the Current Balance $ field. It just displays a blank box.
I can get the ‘Current Balance $’ to display the total $ amount from the table using DSUM (i.e. with no filters applied) but can’t get it to do the above.
Would appreciate your help.
Many Thanks
Remove spaces if ID is text:
=Nz(DSum("[Amount $]","Accruals Raw Data","[Accrual ID]= '" & [Accrual ID] & "'"),0)
and remove quotes too if ID is numeric:
=Nz(DSum("[Amount $]","Accruals Raw Data","[Accrual ID]= " & [Accrual ID] & ""),0)
For two criteria try:
=Nz(DSum("[Amount $]","Accruals Raw Data","[Accrual ID]= '" & [Accrual ID] & "' And [Company] = '" & [Company] & "'"),0)
I have made a search form that allows the user to search within company expense reports for certain clients, projects, employees, and date ranges.
For the Date Criteria Box I have the following formula:
Between [Forms]![Search Form]![txtDateFrom] And [Forms]![Search Form]![txtDateTo]
This works fine but if I don't input any dates then no records show up, I want to change this so that all records will show up if they are left blank.
I've been able to do this for the project, client, and employee fields with the following formulas:
Like "*" & [Forms]![Search Form]![cboProject] & "*"
Like "*" & [Forms]![Search Form]![cboClient] & "*"
Like "*" & [Forms]![Search Form]![txtEmployee] & "*"
You guys probably know exactly what this means but I'll briefly explain it anyways: when I enter something in the textbox for Employee, the combo box for Project, or the combo box for Client in my search for and run the query, only the values that match what I entered appear. The Like "*" bit makes it so that if nothing is entered all the values show up.
I want to do the same for the date range but it is a bit trickier for me to do, can anyone help me with the syntax of this to make my date from and date to boxes show everything if left empty? Because right now if i leave them empty no records are shown which is a huge problem for the user side.
I've tried:
Like "*" & (Between [Forms]![Search Form]![txtDateFrom] And [Forms]![Search Form]![txtDateTo]) & "*"
But it didn't work for me and when I would input date ranges the incorrect date ranges would appear in the query.
What is the correct way to write this?
Sound like now your query returns the correct rows when both txtDateFrom and txtDateTo contain non-Null values.
But you want all rows returned when either txtDateFrom or txtDateTo is Null. In that case you can add 2 conditions to your WHERE clause:
WHERE
your_date_field Between [Forms]![Search Form]![txtDateFrom] And [Forms]![Search Form]![txtDateTo]
OR [Forms]![Search Form]![txtDateFrom] Is Null
OR [Forms]![Search Form]![txtDateTo] Is Null
Dim A As String
Dim B As String
Dim p As String
A = Nz(Forms!frmsearchInv!txtDateFrom, "1")
B = Nz(Forms!frmsearchInv!txtDateFor, "1")
If A = "1" Then
A = "0000-01-01"
End If
If B = "1" Then
B = "9999-01-01"
End If
p = "select * from orders where [orderDate] >= #" & A & "# AND [orderDate] <=#" & B & "# "
i have a table like this and now my task is to fill the empty field with respect to vol and country of the respective column
rule : i have to see the highest volume in the vol field and take the country of that vol and put it in the empty field (ie i have to fill empty cell with country JP because the vol of japan is more )
like this i have to fill .
the remaining fileds like RB , Plant, MCR are changing for remaining empty cells.
i had use Dlookup for this but i coudnt get the solution could any one please help me it is very helpful if you find me the solution.
like this i have to fill all empty line in the table
Ok i am giving more clear view of my table view so that you can understand easily
this is the only table i have to do the task
and now my task is i have to fill the empty cells in the country field but the condition is i should look the RB , Plant ,MCM with respect to vol field (ie: if you see the table the RB , plant ,MCM feilds are same but the country and vol are changing for one group so i have to also consider the fields, that means if the RB, plant, mcm fields are same then i have to take the one of the country in the group with the highest volume) (i just give example in the first thre rows RB , plant , MCM are same so i have to take the highest volume country ie IN so the empty cell should be IN and secodn group empty cells should be TH like that i have to fill.
As I mentioned in my comment to Johnny Bones' answer, your original requirement could have been accomplished with an UPDATE statement that used the DLookup() and DMax() functions like this:
UPDATE MyTable
SET Country=DLookup("Country","MyTable","Vol=" & DMax("Vol","MyTable"))
WHERE Country IS NULL
Even with your revised requirements it is still possible, just more scary-looking:
UPDATE MyTable
SET Country=DLookup("Country","MyTable","RB='" & RB & "' AND Plant='" & Plant & "' AND MCM='" & MCM & "' AND Country IS NOT NULL AND Vol=" & Nz(DMax("Vol","MyTable","RB='" & RB & "' AND Plant='" & Plant & "' AND MCM='" & MCM & "' AND Country IS NOT NULL"),0))
WHERE Country IS NULL
The above query was tested and verified as working in Access 2010.
You can do it in VBA, and have more control over how it reacts. Something like this will do:
Dim db As Database
Dim rec As Recordset
Dim MySQL As String
Set db = CurrentDb
Set rec = db.OpenRecordset("Select Top 1 MyTable.Country FROM MyTable ORDER BY MyTable.Vol DESC")
MyCountry = rec(0)
rec.Close
SetWarnings = False
MySQL = "UPDATE MyTable SET MyTable.Country = '" & MyCountry & "' WHERE IsNull(MyTable.Country) or Len(MyTable.Country) < 2"
DoCmd.RunSQL MySQL
SetWarnings = True
db.Close
I tested the above and it works, although if your table's field's properties are different you may need to tweak some of the code.
Obviously, anywhere you see "MyTable" you should use your own table's name.
I'm pulling information that will eventually be from 5 tables at once based off of a filtering system. Right now I have three different databases running, its looking great. My issue is I have certain fields that I only want to display distinct information on and others i want to display all. To better explain I'm going to give my example.
My select code:
SELECT w.event,
w.city,
w.DATE,
a.TIME,
w.tmc,
a.weather,
a.surface_temperature,
p.top,
p.LEFT
FROM weather w
LEFT OUTER JOIN application a
ON a.DATE = w.DATE
AND a.tmc = w.tmc
LEFT OUTER JOIN pinlocations p
ON w.city = p.cityname
WHERE w.DATE = '" & datepicker_value.Text & "'
AND w.TIME LIKE '" & eventTime.SelectedItem.Value & "'
I have a map which I'm placing pins on based of the p.top and p.left. When I click on this I want to display the city name, the tmc, and then under that all the other information based off the filtered search. In the example above it creates pins on top of pins, making a new one for each field, I want it to be distinct.
I know the distinct command exists, just not sure how to use it in this situation.
Thanks!
Use a group by modifier, on the values you want to be distinct.
Then use a group_concat on the values you want to have listed in a comma-separated list.
SELECT group_concat(w.event) as events,
group_concat(w.city) as cities,
group_concat(w.`DATE`) as dates,
group_concat(a.`TIME`) as times,
group_concat(w.tmc) as tmcs,
group_concat(a.weather) as weathers,
group_concat(a.surface_temperature) as temperatures,
p.top,
p.LEFT
FROM weather w
LEFT OUTER JOIN application a
ON a.DATE = w.DATE
AND a.tmc = w.tmc
LEFT OUTER JOIN pinlocations p
ON w.city = p.cityname
WHERE w.DATE = '" & datepicker_value.Text & "'
AND w.TIME LIKE '" & eventTime.SelectedItem.Value & "'
GROUP BY p.top, p.left
If a left-top coordinate only ever links to one city (as you'd expect), there's no need to put it inside a group_concat statement. Nor does MySQL require* you to put it in the group by clause.
See:
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat
* ) you can force MySQL do enforce strict group by rules, but by default it is off.
You cannot use distinct here, because distinct is an all or nothing affair, it operates in the collectivity of all selected values, not just on one field.