In an Access form, I have a textbox with a control source as follows:
=DSum("Site","tbl_data","Fin_Year='2010' and Qtr='Q1' and IDx='2.2b', IDx='2.4',IDx='2.6a''")
I want to get the total using the dsum function from 3 specified fields in IDx but it returns #Error.
Try with the correct syntax:
=DSum("Site","tbl_data","Fin_Year='2010' And Qtr='Q1' And (IDx='2.2b' Or IDx='2.4' Or IDx='2.6a')")
or:
=DSum("Site","tbl_data","Fin_Year=2010 And Qtr='Q1' And (IDx='2.2b' Or IDx='2.4' Or IDx='2.6a')")
Related
This time I'm trying to work on an MS Access application. I have a split form populated using a SQL query. Now I want to filter this form using a combobox which is located in the header of the form. This CB is also populated with a SQL query:
SELECT DISTINCT [ConsultQ].[ClientName] FROM ConsultQ;
I have added an embedded query to this Combobox which should filter the form. The values shown in the Combobox are correct. But when I select a value from the box a popup show which asks me for input.
The ApplyFilter action is set to:
So, apparently, the ApplyFilter action cannot retrieve the selected value of the Combobox. What am I doing wrong here?
When I enter a name in the input box, the filter is applied correctly. So the filter works, but I cannot set the filter using the selected combobox value.
It must be something simple, but I cannot find it.
I'm using MS Access Office 365 version.
Remove the [Text] property. You want [Value] and [Value] is the default so doesn't have to be explicitly referenced.
Also need full path reference to combobox.
Forms!yourformName!cboClient
However, really should use ClientID to filter records. If the combobox has ClientID as first column and first column is set as the BoundColumn, then combobox value is ClientID, not ClientName.
I have been trying for several hours to resolve my problem myself but with no luck.
The controls I have are as follows
Userform - [frm_Team_View]
Listbox - [lst.Team] (column 0=Name, column 1=Initials, column 2=manager, column 3=hours worked)
I am trying to calculate the total hours worked for the whole team and display this in textbox - [txt_THours].
I have tried to do this in VBA using DSUM & SUM
I have also tried the same methods using the Control Source.
txt_THours.Value = Sum(Forms![frm_Team_View]![lst_Team].column(3))
Each time I keep getting a #Error message displayed in the textbox.
I managed to get a count of the rows in the listbox by using the .listcount function. I have not been able to find a function to sum the values.
The Query is run directly from the listbox so is not saved seperatly. I am unable to save the query seperatly as this will not allow other functionality I have on the userform.
Many thanks in advance
It is not possible to sum the values in a listbox with an expression.
I assume you build the RowSource of the listbox dynamically? When you do this, save the WHERE clause in a variable, and use the same WHERE clause in a DSum expression for the textbox.
Or run a VBA loop over the rows after setting the RowSource, but that seems a little silly.
For i = 0 To Me.lst_Team.ListCount - 1
mySum = mySum + Me.lst_Team.Column(3, i)
Next i
I managed to resolve this question after several hours.
Please see below
txt_THours = DSum("[Hrs]", "Manager_Query")
I have a query that returns a fluid # of records, depending on criteria selected in the form. I would like to display the total # of records returned to the form.
I have added a unbound text field to the footer in the form that is displaying the controls and resulting records. I tried the following expressions in the text field, both of which result in #error:
=Count([qrnname]![fieldtocount])
=DCount([qrnname]![fieldtocount])
This should be simple.
DCount requires string values for its arguments. Assuming fieldtocount is the name of a field returned by the named query qrnname, use this as your text box's Control Source ...
=DCount("[fieldtocount]", "qrnname")
Since that query depends on criteria selected in the form, Requery the text box whenever those criteria change to update the count displayed in the text box.
use this =DCount([fieldtocount]![qrnname])
The syntax for the DCount function is:
DCount ( expression, domain, [criteria] )
expression is the field that you use to count the number of records.
domain is the set of records. This can be a table or a query name.
criteria is optional. It is the WHERE clause to apply to the domain.
Dcount in detail
An other alternative is to use =Count(primaryKey) in the Control Source property
It seems better if you have some filter on your original query, so you don't have to apply them again in the DCount (expression, domain, [criteria]) function.
A quick method for counting Access records in a form
I have a data set that is returning two properties, a name and a total units. I am trying to set an iif expression on a data bar where iif(field!Name.Value = "Name", field!Total.Value, 0)
this is not working I get an error of rsFieldReferanceAmbiguous, the fields refers without specifying a dataset aggregate. And the only option that it gives me as an aggregation is First, but I do not want to get the first name, I want the bar to display the total units base on the name field that is in the iif expression.
rsFieldReferenceAmbiguous refers to trying to match something that is not in local scope. Therefore you have to aggregate it. You are probably wanting something like this:
=Sum(IIF(Fields!Name.Value = "Name", Fields!Total.Value, 0))
The function you are trying to use would be better suited to a calculated field in your dataset. Then you can just refer that that field in your report. This allows you to filter the data line by line instead of by groups.
Right-click on the dataset and go to Dataset Properties.
Go to Fields.
Click Add then Calculated Fields.
Enter the name of the field and then the expression here.
Make sure your tablix has the dataset specified under General -> DataSetName on the properties pane. If you have more than one data set on the report you will need to specify which data set your reffering to like so:
(Fields!Name.Value, "NameDataSet")
If your useing tables you may need to ckeck if you have grouping and if so how your grouping your data.
Guys...if I want to run a button click event that takes a list box and uses the ID field that is in the listbox in a SQL statement in VB, then is it
me.MyListbox.selected
or
me.MyListbox.value
to get that value? for some reason I have tried both and neither seem to be working. .value returns an empty value, and .selected generates an error stating the argument is not valid.
thanks
justin
If the ID is the bound column and the listbox is not multiselect, you can use just the name of the listbox without any other qualifier. If the ID is not the bound column, then use the column property to get the value : MyListBox.Column(n) where n is the column number starting from zero.
For multiselect listboxes, you need to iterate through the selected items to get a list to use with SQL.
If you are using the query design window or a control on a form or report, you cannot use Me, you must either use the full reference (Forms!Formname!ControlName) or for a control on the same form, just the name of the listbox.