MS Access uses a form field in query but prompts for parameter - ms-access

I have a form with two dependent comboboxes (the second loads its values depending on what is selected in the first one). The second combobox uses this query in its RecordSource property
select... where id = [Forms]![MyForm]![myField]
My problem is that I choose the myField in the expression builder and so it allegedly generates the bracketed part correctly, but when I run the form Access doesn't understand it and always prompts for a parameter named with that expression [Forms]!...etc.

Solved as per post comments by Gustav:
Try specifying the field only: select... where id = [myField].

Related

MS Access using ApplyFilter from Macro Builder with combobox shows input parameter box

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.

Report Builder - Use one dataset in the where clause of the query for another dataset

I'm using SQL Server Report Builder 2014.
DatasetA is created from TableA in DatasourceA and contains a single column of IDs.
DatasetB, on which my report is based, needs to have all rows from TableB in DatasourceB WHERE TableB.ID IN (DatasetA).
I've done lots of Google'ing, but cannot find a solution that works. Suggestions?
For this you could use a hidden parameter in the report, lets call is ParamA. Populate ParamA using DatasetA, set it as a multi-select parameter and set the defaults using DatasetA i.e. all items will be selected.
Then in DatasetB have where id in (#ParamA)
As I know, when you use where name in (#aa) in query designer(text mode) and click OK, it will prompt like below
You could hard code in it, it seems to support single parameter to test in designer, but when you preview it in report, you could pass multiple parameters. You could click OK to ignore it or pass hard code in it to see whether parameters could work or not.
In addition, if you want to show dataset A's value in parameter list, you could set available value in parameter properties (get values from query)

Access 2013 primary key in where condition of macro builder

I've searched the web and this site but have not seen an answer to my particular question. I want to produce a report based on the current record (easy), but with the primary key as the Where Condition (not so easy). I'm hoping to use the macro builder and avoid VBA, if possible.
In the macro builder, I can easily get this done by inputting "[First Name]=[Reports]![Contracts]![First Name]" in the Where Condition. 'First Name' is just a regular field present in both my main table and the report. However, customer names can change easily so I'm hoping I can use the primary key "Id", as that should be a more reliable and unchanging value. But if I try with "[Id]=[Reports]![Contracts]![Id]", I get the whole 'Enter a Parameter' dialog (and even if I input the Id value, it just outputs every record).
Why does this work with the First Name field but not the Id field? Is it because Access doesn't like to use primary keys for the Where Condition? If I use the expression builder, Access will recognize the Id field as present in my report and (therefore, I would think) as usable for this purpose. I'm assuming I'm missing something on the left of the equal sign? I've tried with Me. and Me! before and inside the brackets, but nothing. I've also tried stuff like "[Tables]![Main]![Id]=[Reports]![Contracts]![Id]" and "[Main]![Id]=[Reports]![Contracts]![Id]".
You could try creating a temporary variable and pass that to the open report action.
For example, let's say you want to open a report for a record when the user clicks on the field 'First Name' for that record in datasheet view. Your On Click embedded macro would be:
SetTempVar
Name tmpID
Expression = [Id]
OpenReport
Report Name Contracts
View Report
Filter Name
Where Condition = [Id]=[TempVars]![tmpID]
Window Mode Dialog
RemoveTempVar
Name tmpID

How to display a query record count in a form control

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

Access 2007 Using the ID value from a list box in VBA/SQL statement

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.