I am currently using multiselect comboboxes to specify filters for a query (that will go on to generate a report).
I have it all working fine, apart from the fact I would like to specify default values to each of these comboboxes when the form is loaded.
It seems like using the builtin default box in the property panel doesn't accept multiple values (or rather I don't know how to give it multiple values)
I have tried selecting the values I want at runtime using the Selected property of the control:
For i = 0 To Me.MyComboBox.ListCount - 1
Me.MyComboBox.Selected(i) = True
Debug.Print Me.MyComboBox.Selected(i) 'Returns false
Next i
But unfortunately that doesn't work. It doesn't give an error or anything, but setting it just doesn't seem to change the value.
Does anyone have any idea on how to achieve this? I would essentially like to go on to have an "All" button next to each combobox that selects all the values in the combobox, so preferably a VBA approach to the problem would benefit me the most.
Any help is much appreciated
Add the following before setting the Selected property:
MyCombobox.SetFocus
MyCombobox.ListIndex = 0
Related
I'm quite new to VBA and I've been looking around but cannot seem to find a solution to my problem.
I have made a navigation form (frmNavigation) with 3 buttons, each referring to a different form, let's call them frm1, frm2 and frm3. In the navigationform the control buttons to switch between tabs are all named differently (btn1, btn2, btn3), but the subform that shows either frm1, frm2, or frm3 has the same name: “NavigationSubform” (this shows a different form depending on which tab is clicked on, based on the 'navagation target name' referring to frm1, frm2 and frm3).
When I want to refer to a textbox (txtBox1) on form 1 (first tab) and insert a value i can do this by:
Forms!frmNavigation!NavigationSubform.Form!txtBox1.Value = "insert awesome text"
But how would I refer to txtbox10 on the second tab (frm2)? Just using the following does not work:
Forms!frmNavigation!NavigationSubform.Form!txtBox10.Value
You then get the error 2465 (can't find the field).
I’ve been trying many different things, but can’t seem to get it right. So how do I refer to a textbox on a different tab than the first one?
Help us much appreciated!
Only one subform can be loaded at once. So you've just got to break this process into two steps.
Store the value from txtBox1 somewhere outside of the NavigationSubforms (a textbox on the parent form with visible = no, a global variable or a table works).
In frm2's On Load event, set txtbox10 to be the value you stored.
Just note, that you will need to add conditions in the On Load event if you want to avoid that textbox being set to an empty string or a wrong value if you have a setup where your filter is changing.
My combobox has 5 values, and three of them contain a particular word that, if selected, should enable two other controls on the form that would be otherwise disabled. I already figured out how to enable/disable the controls but im trying to figure out the correct syntax for the code that would check if these values are selected or not, but cannot find a clear format of code. Please help.
If your combobox only has 5 values and is limited to those 5 values, then just use the whole value and not the containing word.
private sub cmb1_AfterUpdate()
if me![cmb1].value ="value1" Or me![cmb1].value ="value2" Or me![cmb1].value ="value3" then
me!txtbox.enabled = true
else
me!txtbox.enabled = false
end if
end sub
Good Afternoon,
I have a multivalue parameter where if the last value in the array has the value "Reentry", it should always display the report. However, if the last value in the array is not "Reentry" it should hide the chart because it doesn't apply to the other choice. The choices are Corrections, Reentry and All. I applied the following expression to the visibility option of the target chart.
=IIf((Parameters!Division.Value(Parameters!Division.Count-1)="Reentry"), True, False)
This is showing the report for all cases, even when I select only Corrections which is the value that appears in a textbox where I placed this expression, being the last value in the array.
=Parameters!Division.Value(Parameters!Division.Count-1)
I have tried all kinds of other ways to get this to work and I have been stuck for a day. I think this approach is the easiest but it is always showing the chart, no matter what is selected. Any thoughts? This shouldn't be so difficult...thanks in advance!
Try using this expression:
=IIF(
Array.IndexOf(Parameters!Division.Value,"Reentry")=
Parameters!Division.Count-1,True,False
)
Let me know if this helps.
I have a form, frmResults, which contains a subform control, frmResultsSub.
frmResultsSub is a subform control which contains a query instead of a form. In other words, its SourceObject property is set to the query, "Query.qrySearch"
Is there any way I can reference the fields of this query to e.g. to centre text or change field width?
I've tried these statements in the Open Event for frmResults, but neither was successful:
Me!frmResultsSub.fldA.Width = 600
Me.frmResultsSub.fldA.Width = 600
Reference the fldA field in the query the same as you would if it were the name of a textbox on a form contained in that frmResultsSub subform control.
Put this in On Load and verify it shows you the field name instead of triggering an error ...
MsgBox Me!frmResultsSub!fldA.name
Once you have that working correctly, you can work with the column's properties. During On Load, adjust its ColumnWidth property to change its width ...
Me!frmResultsSub!fldA.ColumnWidth = 600
That should allow you to set the width. But you also mentioned text alignment, and I don't see how to do that for a query column unless you create an actual form based on the query.
I don't think you can adjust column width on a query using VBA. You can however solve your problem using one of those methods:
create a form (AutoForm is ok) and make its default view as Datasheet. then use that form as the source of your subform control. that will be visually identical to your current solution.
use a listBox instead of a subform. It's quite versatile and you can easily set the listbox rowSource to any SQL statement. You will have to handle sync with main form data but it is very simple.
Try this: Me.frmResultsSub.Form.fldA.Width = 600
I have a combo box on a form that is linked to a SharePoint field, the combo box populates correctly however I am having difficulty trying to add VBA code to select all of the options or to unselect all options.
With a standard combo box you can use:
cmbBox1.value = ""
and that will reset the field. The same thing can be done with a list box that has multi-select enabled however this tosses an error, "This control is read-only and cannot be modified", with the combo box that has multi-select because of the lookup.
I have done some searching however no one seems to have a real answer other than to use a listbox instead and that isn't a solution here.
Has anyone worked with one of these fields and know how to select all of the options using VBA?
Here is a link describing this type of field but it does not discuss how to interact with it using VBA - http://office.microsoft.com/en-us/access-help/use-a-list-that-stores-multiple-values-HA010031117.aspx.
UPDATE:
There has been some confusion about the type of field I was describing so I have added some screen captures to show the difference between a combo box that allows multiselect, a list box that allows multiple options and a combo box with the option added.
First the field I was describing:
Second the list box:
Lastly the combobox:
These images visualize the issue that was described. As you can see there are multiple check boxes that need to be selected or unselected. Normally I would not create a field like this but as described above this is how Access interprets a combobox from SharePoint that allows for multiple selections.
After a ton of searching and trial and error I figured it out.
To unselect all of the check boxes it is
cmbBox1.Value = Array()
So with this information I figured that to select items they have to be in an array. Creating an array with all of the items that are in the combo box and then setting the combo box equal to the array will select all of the items.
I used a basic loop to set each element of the array
Dim SelVals(), i
ReDim SelVals(0 to cmbBox1.ListCount - 1)
For i = 0 to cmbBox1.ListCount - 1
SelVals(i) = cmbBox1.Column(1,i)
Next i
cmbBox1.Value = SelVals
Obviously then you aren't limited to only using the entire contents - you could assign any array and those would be the values selected.
http://msdn.microsoft.com/en-us/library/office/aa140084(v=office.10).aspx
I beleive this covers what you are asking