Multiple Values for a field (Link Master fields) - ms-access

I am trying to use Link Master Fields to get a value from my form in order to filter some of my data and then show the remaining on my chart. Everything works perfectly fine but when I want to select more than one value (using a listbox to select multiple values for a field), my chart returns nothing.
I would like to know how can I address multiple values for a field in my chart so it filters the values on my chart as an "Or" function in SQL.
Imagine I want to have an SQL with: WHERE [MyTable].[Field1]= Selected values in listbox.
It seems that my SQL selects all the values in the listbox as One Value/And function.

You will need to do this via VBA.
Use the Change event on the list box to update the subforms recordsource.
Also make sure you execute the code in the forms Current event, so that it will display correctly when moving records, and on initial opening.

So with a bit of research and trying out different ways, an easy way is to use some hidden textboxes in the form and loop through the selected values and give each textbox one of the selected values in the listbox.
From there you can write a SQL for your chart specifying the condition so your field = Condition 1 or field = Condition 2.

Related

SQL Select Statement Column Selection Based on Checkbox TickMark Access

I would like to select specific columns based on the user checkbox selection.
I can able to achieve it using VBA but is it possible to arrive the fields in SQL itself based on forms checkbox tick status?
Two ideas:
1) create a text box that collects the values of the checkboxes:
= if(checkbox1,"Col1, ","") & if(checkbox2,"Col2, ","") & ...
Create a second one that removes the tailing comma.
Use the content of this second text box to build your SQL string.
2) Solution 1 requires you to hard code the columns in one formula. A more generic way would be to populate a list with the column names of your data source (the table). The changed event of the list would then generate the list of column names for your SQL string.
This solution involves VBA, yes but it's interactive. Guess that's what you're after.

Trying to populate two comboboxes based upon selection of another combobox

I've been searching this issue on Microsoft, Stackoverflow, techinthenet.com and several others, with no real solution that I can find.
I am trying to get two comboboxes (cboCourse and cboVols) to populate based on the selection of cboTrainee_Name. The code for the first combobox is:
SELECT DISTINCT [qryBooks].[PName] FROM qryBooks WHERE qryBooks.Complete=No ORDER BY [qryBooks].[PName];
Everywhere I've searched gives assistance and samples to populate the first combobox, then the second combobox based upon what is selected in the first. I need both cboCourse and cboVols to populate based on the result of the same query. What I have so far is:
Private Sub cboTrainee_Name_AfterUpdate()
cboCourse.RowSource = "SELECT DISTINCT [qryBooks].[Book] FROM qryBooks WHERE [qryBooks].[PName]=[Forms]![frmIntro]![cboTrainee_Name] ORDER BY [qryBooks].[Book];"
cboVol.RowSource = "SELECT DISTINCT [qryBooks].[Vols] FROM qryBooks WHERE [qryBooks].[PName]=[Forms]![frmIntro]![cboTrainee_Name] ORDER BY [qryBooks].[Vols];"
End Sub
This works for cboCourse, but cboVols will not populate. I know there has to be a simple explanation. Any suggestions?
ADDED! I used SELECT DISTINCT because each column in the query contains multiple instances of the same data.
I don't see any problems with your SQL.
You might need to call the Requery method on both combo boxes to get them to refresh after cboTrainee_Name is changed:
cboCourse.Requery
cboVol.Requery
Note that you don't have to set the RowSource property in code for this to work. You should be able to plug in your SQL statements as is in the RowSource property and just the Requery method on the dependent combo boxes in the AfterUpdate event of your cboTrainee_Name combo box.

Enable Selection of only two values in SSRS multiple select parameter

I have a SSRS report in which i have a parameter which comes in a dropdown it is a multiselect parameter, now i want that at most user should be able to select only two values from the dropdown.
Although you can't stop the user from selecting more than two values, you can keep the report from being shown if they do. First, I created a red-text textbox at the top of my report that holds an error message. Something like:
You selected more than two values for ReportParameter1, try again...
Then, I set the visibility of this message with an expression (for hidden) set to =(Parameters!ReportParameter1.Count<=2). Now this error will show only when the user has selected more than two parameters.
I then hide the content of my report with a visibility expression of =(Parameters!ReportParameter1.Count>2). Note that you can simply put all your content in a rectangle and then hide the rectangle.
If your user selects more than two parameters, only the red error message is shown. If they select two or less, everything looks normal. I would also write your stored procedure in a way so that if a user selects too many values for the parameter, it won't return any data.
This is not possible. A multi-select parameter is that and just that: a parameter that lets you select multiple values.
If you will always only have two values that need selecting, the easiest way of implementing this would be to have two single value parameters labelled as Value 1 and Value 2 which are then both referenced in your report query.
There are workarounds as suggested by #Kyle Williamson in his answer, but there is no exact answer possible as this facility is not present in SSRS

Populating listbox from another listbox selection

I am pretty much a newbie to using VBA in Access and I'm having trouble with something that seems like it should be quite simple.
I have two listboxes (called LB1_ID and LB2_ID) on my form (MainForm) that I want to list related IDs from their respective Row Sources. I need LB2 to be populated based on the selection in LB1. They both have Row Sources from the same Table (Table1) and it is a many to many relationship of Requirement IDs ("Req ID1" and "Req ID2"). My current form, which is not working, has the Row Source of LB1 as:
SELECT Table1.ID, Table1.[Req ID1] FROM Table1 ORDER BY Table1.ID;
and the Row Source of LB2 as:
SELECT Table1.ID, Table1.[Req ID2] FROM Table1 WHERE ([Forms]![MainForm]![LB1_ID]=Table1.[Req ID1]);
When I make a selection in LB1, nothing happens in LB2. The column widths are formatted correctly and I can get it to work if I use Me.[Forms]![MainForm]![LB1_ID] but I have to type out the LB1 selection manually in a popup box if I use that.
What am I missing?
If your listbox is multi-select, you cannot use a simple form reference as query criteria. If it is not multi-select, keep in mind that its value may be a hidden column (usually an ID field), so there are two possible issues and solutions:
Possible Issues:
Single-Select listbox has an ID field that is hidden (column width = 0") and you are matching it to the wrong field in your table. To check the output of the listbox, open the VBE and type ?[Forms]![MainForm]![LB1_ID] into the immediate window and press enter when your form is open in form view and a row is selected in LB1_ID. If the returned line is what you expect, then the problem must be elsewhere.
Multi-Select listbox property is enabled. In this case, your query will not work, because the listbox will only return Null. You will need to write some VBA to loop through the rows and figure out which ones are selected, which is a bit of a pain. Ultimately you'll build some code that will alter your query with the specific criteria for each selected row. Instead of explaining here, take a look at this article for a tutorial.
The .Requery method is still important to put in the AfterUpdate event of your first listbox to refresh the second.
Your query seems to work, but you need to refresh your listbox2 whenever you make selection into listbox1, so if both listbox are in the same form add this event handler :
Private sub LB1_ID_Change()
Me.LB2_ID.Requery
End sub
Without this, your listbox2 will only get populated once on load based on the initial value of listbox1.
Also, if you have not already done it, I would recommend to add your listbox1 control as a parameter into your listbox2 query (in query builder, right click -> parameters).

Access Query Parameter Filtering Form

I am filtering a form named sfrWorklistFilter from a combo box named cboOpeningType. The recordsource is from an embedded query on the form. If I make a selection from the combo box the filter works fine with the following code:
Forms![sfrWorklistFilter]![cboOpeningType]
However I need to return all records when no selection is made in which case I use the following code:
Like Forms![sfrWorklistFilter]![cboOpeningType] & "*"
The filter then does not give exact matches, but all records that begin with the letter on the combo box.
I need exact matches for the record or if no selection is made all records.
Any suggestions?
EDIT remove double quotes
This should work - and you can do same thing with your other field/combobox searches
Like IIf([Forms]![sfrWorklistFilter]![cboOpeningType]<>"",[Forms]![sfrWorklistFilter]![cboOpeningType],"*")