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

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.

Related

Using a calculated field value from a form text box in a query

I have a calculated text box on a form. How can I use that value in a query? The value is based on many other calculations done on the form as well.
I was hoping I wouldn't have to re-do all the calculations in the query.
Providing the form remains open when the query is evaluated, you can reference the value of any control on the form using the following syntax in your query:
Forms![Your Form Name]![Your Control Name]
In the case of referencing the value held by a control on a subform, consider that the subform is just another control on the parent form, and so the chain of references becomes:
Forms![Your Form Name]![SubForm Name].Form![SubForm Control Name]
You can test the value obtained by simply creating a new query in Access with the SQL code:
select Forms![Your Form Name]![Your Control Name] as FormValue
When run, this will yield a single record displaying whichever value was held by the control Your Control Name on the open form Your Form Name at the time of execution.

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

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].

How to get a subform field value?

I have an Access form with (continuous) subform and one of the combobox fields on the subform is populated with data depending on the value of another field.
For this I use the following in the Data Row Source:
SELECT VendorName FROM VendorsPerAction WHERE (Action= Forms![LocalSubformActions]![fldAction]) UNION SELECT distinct null FROM VendorsPerAction ORDER BY VendorName;
This works fine when I test the form outside the mainform. But when I test this as part of the mainform Access keeps asking me for the parameter. I tried changing it into:
(Action= Forms![LocalRequest].[LocalSubformActions]![fldAction])
and many other variations but I keep getting the parameter question.
Is there anyone who knows what I should use? Thank you!
Probably
Forms![LocalRequest].[LocalSubformActions].Form![fldAction]
(assuming the subform control has the same name as the subform)
See Refer to Form and Subform properties and controls
--> Forms!Mainform!Subform1.Form!ControlName

How to use a query as a source for a report in MS Access 2007?

I did the following in MS Access: I made a form which had a combo box and a button. You select an option from there and click on the button and it is supposed to open a report. Now, I wrote a query selecting a few fields from a table and in the where clause, gave the condition as where name=str(combo1.value) and the report source was specified as this query. Now, when I select the value and click on the button, it opens a blank report. How can I make it load only those particular values?
I am not saving the combo box value anywhere. It said that it would remember the value for later use. Am I doing the right thing by not saving it? What should I do to make this work? Please help me!
Edit: The combo box is using values from a column 1 in a table X. I've not bound the value to any field and am using the "Remember the value for later use" option provided. The combo box is essentially a list of hotels and the report is a list of people staying at the selected hotel. When I put the ID of the field (as defined in the X), it works. But the thing is, it should refer to the names of the hotels and not the ID, which I am supposed to enter in a popup that asks for it. What do I do?
Edit 2: The query is as follows:
SELECT Table_1.Hotel_Name, Table_2.Name_of_Delegate, Table_2.Address, Table_2.City, Table_2.Center, Table_2.Spouse_Present, Table_2.No_of_Children, Table_2.No_of_Guests, Table_2.No_of_Rooms
FROM Table_1 INNER JOIN Table_2 ON Table_1.ID=Table_2.Hotel_of_Residence
WHERE Table_1.Hotel_Name=FormName.Combo7.Text;
When I click on the button (which opens the report), it asks for the name of the hotel in a popup box. How can I avoid this? What I am doing wrong?
You can use a WhereCondition with the DoCmd.OpenReport Method as a "dynamic WHERE clause" for your report's record source. Use something like this in the click event of the command button which opens your report.
DoCmd.OpenReport "YourReport", , , "[name]=" & Me.combo1
Remove the WHERE clause you added, where name=str(combo1.value), from the report's query.
I surrounded name with square brackets because name is a reserved word. See Problem names and reserved words in Access
Edit: In a comment, you said this about the combo box:
"Row Source is SELECT [Table_Name].[ID], [Table_Name].[Name] FROM [Table_Name];. Bound Column is 1 (which I assume shows the names I wish to be displayed in the combobox.)"
When you refer to the value of a combo box, that value is the value of the "Bound Column". So in your case, the bound column is 1, which means the combo value will be [Table_Name].[ID]. However, you want to open your report based on the [Name] column of the combo. So change the bound column of the combo from 1 to 2.
To open a report using the value of your combobox, in your report query you need to do the following:
SELECT fields
FROM table
WHERE YourValue = [Form]![FormName]![ComboBox Value]
You have to specify the name of the Form, plus the value so the report query knows the value. Hope this helps.

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.