MS Access - Expression not identifying contents of combo box? - ms-access

I am very new to MS Access and am trying to get an expression in a query to use the selected text in a combo box, however when I run the query a blank is returned for the selected field. The intention is for the user to be able to select an option from the drop down list in the combo box and then press a button to run the query to bring up all info on that option. The expression is as follows:
[Forms]![Policy_Interactions_Form]![PA1Combo]
What could be causing the expression to return blank values when I can see a selected value in the combo box?
When viewing the query in SQL view it looks like this:
SELECT Policy_Interactions.[Policy Area 1], Policy_Interactions.[Policy Area 2], Policy_Interactions.Interaction, *
FROM Policy_Interactions
WHERE (((Policy_Interactions.[Policy Area 1])=[Forms]![Policy_Interactions_Form]![PA1Combo]) AND ((Policy_Interactions.[Policy Area 2])=[Forms]![Policy_Interactions_Form]![PA2Combo]));

Related

ms access unwanted "Enter Parameter Value" when using combobox in a form

I have form which contains a few combo boxes and some text boxes. There is another combo box (the row source is from another table) which needs to be filtered by the values the user entered in the previous combo boxes and text boxes but even if you entered the values you get the "Enter Parameter Value" message for each one. I used the expression builder for every criterion so its unlikely that there are any typos. What can cause this message to appear?
Code for the combo box's row source:
SELECT Profiles.profile
FROM Profiles
WHERE (((Profiles.Type)=[Forms]![AddItem]![typeComboBox]) AND
((Profiles.WindowOrDoor)=[Forms]![AddItem]![windowDoorComboBox]) AND
((Profiles.MaximumWidthPerWing)>[Forms]![AddItem]![widthUserInput]) AND
((Profiles.MaximumHeightPerWing)>[Forms]![AddItem]![heightUserInput]))
The SQL statement is in the RowSource, not a query object? If the controls are all on the same form, no need for the full form path reference. Works for me. Try:
SELECT profile
FROM Profiles
WHERE [Type] = [typeComboBox] AND
WindowOrDoor = [windowDoorComboBox] AND
MaximumWidthPerWing > [widthUserInput] AND
MaximumHeightPerWing > [heightUserInput]
I think Type is a reserved word, hence the [ ].
If it still prompts for input then Access can't find those names.
You also need code to requery the combobox. Put it in the form Current event as well as the combobox GotFocus event.
Be aware, cascading combobox doesn't play nice with continuous or datasheet form.

displaying query results on sub form in MS access

I have a Form A (Main form) with combo box taking values from a account master table. Whichever value a user will select from combo box is displayed on the same form in 2 text boxes. Now on pressing a button (On Form A) a query A runs after taking the values in 2 text boxes as inputs.
The results are displayed correctly in a separate tab created automatically in datasheet view.
However I want to display the results on a sub form on the Main form A. I have bound this sub form with the Query A and have placed this sub form on form A.
But still the query results are getting displayed in a separate tab and not on the sub form which seems to do nothing.
Please help.
If the results of the query that you are using as the Source Object for your subform are using the values of the comboboxes as query criteria, you may need to call SubformName.Requery after changing the combobox values.
If instead you are modifying the SQL behind your query rather than using criteria, I have found that you need to issue the following in order for the results to update:
SubformName.SourceObject = Subform.SourceObject
In my experience, when the SQL behind a query that is used as the Source Object for a subform is modified, the data displayed by the subform is not updated following a call to .Requery, but only after the SourceObject property is 'refreshed' using the method shown above.

Combo Box in Ms Access does not dispaly values

I have a comobo box in ms-access whose record source is a query:
select WeightUOM from Ctr where WeightUOM="lbs" or WeightUOM="sh t".
When I run my form the combo box does not display any value.Although running the query independently fetches correct result.
Thanks!!

MS Access 2013 - Filter values in a list box, based on value in a Text box

I have made a form with a Listbox displaying a lot of names and addressees based on a query. How can I filter the names in the form, based on a Text box in the same form?
(Not all the names are relevant for every record)
The listbox has a RowSource, so you can modify it on the fly:
Me!Listbox.RowSource = "SELECT .... FROM .... WHERE ..."
Me!Listbox.Requery
to modify the SQL with the value in the Textbox, use the Textbox AfterUpdate event

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.