VBA Multiple Objects with 'With' Statement - ms-access

I have a check box that when checked multiple boxes are disabled on my form.
Currently im using
With Me!Textbox
.Locked = True
Is there a method where I can list multiple objects within the With statement rather than writing out each time for every textbox
e.g.
With Me!Text1, Text2, Text3

It may be easiest to add something to the tag property to identify the relevant controls, "lock", say. Then you can iterate over the controls collection and lock anything with a tag set to "lock".

Related

Paste a value in a textbox on the second tab of a navigation form access vba

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.

Giving a multiselect combox a default (set of) value(s)

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

Accessing ListBox selected item via UiApp.getActiveApplication().getElementByID()

Currently I am using UiService to create a form and I uses ListBox, from what I understand to pass a value via handler will be something like e.parameter.[Name of ListBox] to access the selected item.
Does anyone know is it possible to use like app.getElementById([Name of ListBox]) to access the selected item. The reason I am using this method is because my list of ListBox-es are dynamic.
I spent some time looking for this answer as well, but finally I tried one idea and it worked.
You can use e.parameter as an array so you can these two will give the same:
e.parameter.LIST_BOX_NAME
and
e.parameter['LIST_BOX_NAME']
So in the second sample any dynamic list box ID can be used. I use same handler for all added dropdown list and have this code to check what dropdown was changed and what value it has now:
if (e.parameter[e.parameter.source] == 'a'){
To change the content of the listBox you can use app.getElementById('ID of the listBox'), from there you can clear() and addItems again but you cannot read the listItems.
When I need to do this I usually store the list of items somewhere else, in a place that I can read anytime, for example the list of items can be stored as a string in the listBox tag itself so I have all items at hand to repopulate the listBox after I have clear it.

It is possible to add to Unordered List during runtime

I have a simple HTML page with an Unordered list. Is it possible to have an input field where you could add more to the list and it would be saved after you submitted it. What I would like to add would be the content inside of an <li> tag as well as the <li> tags themselves.
Thanks,
Here is a jsfiddle with a demo of what I think you want to achieve: http://jsfiddle.net/mvJNq/25/
Note that I can not answer as to how you should do this on the server, as that depends on how your serverside code, database etc is set up. However, if all you want is to display it as HTML and not have it saved as the user navigates away, you won't need the Submit button at all - then you just need the "Add" functionality.
Yes, it is possible - no, it will not be pretty. Here is what you would do:
create your base form with any default list items/inputs
use jQuery/JavaScript to bind an event handler to a button that you click when you want to add another item (alternatively, you could skip this step and just have another item appear by default)
on your event (be it checking that all input boxes have user-entered text, or the click event in step two) add another list item using jQuery.append(...)
ensure that you have a hidden input field to be used as a "counter" to keep track of the total number of list items and increment the value of this counter each time you add a new list item (note: you may need to use the ParseInt() method, depending on how you design the code for this field)
the page that is receiving the form's inputs should first read the hidden field so that it knows how many items to add, and then you should loop through the items (for or while loop) to add them correctly
Note: I don't know what Server-Side language you are using to handle receiving the form so step 5 is a fairly generic and universally viable option
Sure, it's possible.
The complexity of this comes in when you want to "save" the items. If the user leaves the page and comes back later will that data be available? If so, you will need a database like mySQL or similar. The li tags can be stored as well, but why?
If you just need that information available in that session you can store in a JavaScript variable and have it loop through the variable and spit them out as <li>'s
If you did want to use an add button instead of submit:
$('#addButton').click(function(){
var savedContent = $('#input').val();
}
To create + insert the <li>you can use javascript to create the element and append it to the ul. If you have more than one ul change the index:
var content = document.createElement('li');
content.innerText = savedContent;
document.getElementsByTagName('ul')[0].appendChild(content);

Compound object in HTML <button> value attribute

If for some reason it were mandatory to associate a <button> with more than one value, is there a good way to do it? For example ...
CSV:
<button value="Lancelot,Grail,blue">Answer</button>
JSON:
<button value="{'name':'Lancelot','quest':'Grail','color':'blue'}">Answer</button>
In the absence of a good way to do it, is there a traditional way?
Edit: another use case
Server M, the producer of the HTML, knows the user's current location and favorite genres, movie names, nearest theater, and next showtime. Server F knows how to query various 3rd party servers about how to get from point A to point B in order to arrive by time T. The user knows only the movie names: click Drag Me to Hell, and get the route. Server M could generate a form for each movie, with a single button showing the name of the movie and multiple hidden fields with the start and end locations and desired arrive-by time, but that would require a lot of repeated code. Every one of these one-button mini-forms would have the same method and action and the same hidden input field structure. Styling would be a collection of mini-forms rather than a collection of buttons, so FIELDSET and LEGEND are unavailable (because HTML forbids nested forms). Putting the parameters into the button's value attribute would be much tidier.
Well if you have to have a button element, why not use JavaScript to set a bogus property:
$('mybutton').compoundValue = { ... json ... };
and then reading the 'compoundValue's during form submit, etc.
Though really you might want to consider a group of checkboxes or some other form bits for what you're trying to accomplish.