Selecting and clicking an HTML option via automation using ie.DOM in VB - dom

I'm unable to select an option and click it programmatically vai ie.DOM. Here's what the HTML looks like with the options and the onchange javascript call:
And here's what the dropdown looks like:
Here's what I tried that doesn't seem to have any effect on the page
Set ddl = ie.Document.getElementById("ddlReports")
For Each itm In ddl.getelementsbytagname("option")
If itm.Value = "12" Then itm.SELECTED = True: Exit For
Next itm
itm.Click
I've also tried this but it just clears the page and returns a 0.
ie.Navigate "javascript:setTimeout('__doPostBack(\'ddlReports\',\'\')', 0)"
It's supposed to reveal a button that allows me to retrieve the report.

Turns out that I needed to submit the form after selecting an option in the dropdown. Here's the code that worked.
Set ddl = ie.Document.getElementById("ddlReports")
For Each itm In ddl.getelementsbytagname("option")
If itm.Value = "12" Then itm.SELECTED = True: Exit For
Next itm
ie.Document.getElementById("frmAshleyExtracts").Submit

Related

Open Form to a value selected on ComboBox - Ms Acces

I want to open a form to a specific record based on the value is selected on a comboBox. I have written a code and its working, but before opening the form it shows a dialogue box with input field asking for the parameter i want for the form which i dont want the VB code to ask.
DoCmd.OpenForm "Final_Exam", acNormal, , "[admclass] = " & Me.Combo4.Value & ""
This is the code i have written and the requirement is that on clicking the button the form opens without any dialogue box asking for parameter. thanksa
What I've found is the best way to open one form from another is to use OpenArgs. When opening Form 2 from Form 1's button, use code like this:
Private Sub cmdOpenOtherForm_Click()
DoCmd.OpenForm FormName:="frmOtherForm", OpenArgs:=Me.Combo4.Value
End Sub
Then, in the Load event of Form 2, use the openargs to set up your filter:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me.Filter="[admclass]=""" & Me.OpenArgs & """"
Me.FilterOn = True
End If
End Sub
If the field you're filtering on is a text field, make sure to properly escape double quotes (as is done above).

selecting records on a continuous form, sending to a single form- access 2016

I have a continuous form to which I added a checkbox column for each record. I'd like to click on the checkbox and open a single view form for that specific system_id. This is my current code, it's prompting me for an ID field but when I enter the system_id field nothing happens. I don't want a prompt but rather have it seamlessly open the record into the single form. Continuous form is called: [P2P cases] and the single form is called: [P2P View]. Advice please!
current (not working) code:
Private Sub View_Click()
Forms("cases").Form.[P2P View].Form.Filter = "qaID=" & Me.system_id.Value
Forms("cases").Form.[P2P View].Form.FilterOn = True
Forms("cases").Form.[P2P View].Visible = True
If Me.system_id.Value = True Then
Forms("cases").Form.[P2P View].Form.system_id.SetFocus
End If
End Sub

Preselecting Options not working in web2py

I have looked at the documentation at http://www.web2py.com/books/default/chapter/29/05/the-views?search=OPTION%28 and I have looked at the previous question How to preselect options in SELECT helper in web2py, but my selects have not been working properly.
I make the select:
select = SELECT(_name = attr)
I populate it by appending options in a loop
...
option = OPTION(the_string, _value=str(row.id))
select.append(option)
...
I set the selected value for the select
select.value = str(selected_value)
But the select does not have anything pre-selected. In the html, the correct option is not marked 'selected'. What am I missing?
value is an argument of SELECT.__init__ -- it is not an attribute that can simply be set after the object is created. If you want to change the selected attribute of an option after it has been created, you can do:
select.element('option[value=%s]' %
str(selected_value))['_selected'] = str(selected_value)
Or just specify the selected option when creating the OPTION object:
OPTION(the_string, _value=row.id, _selected=True)

ACCESS: Ticking checkbox on form if a value beginning with "(REF)" is selected from combobox

I am trying to tick a check box on a form when I select one of many combobox values that begins with (REF) - this is code that stands for Referral closure.
this is what I've done..it's not working
Private Sub ReasonForInappriopriateReferral_AfterUpdate()
If Me.RsnForInappropriateRef.Value Like "(REF)*" Then
Me.Check66 = True
End If
End Sub
Please help, I was previously trying to conditional format a label to a different colour if the closure reason was a Referral closure, but couldn't do that either and think it could be down to the IF Like command.
I added two controls exactly as you indicated. I populated my combo by setting the Row Source Type to a Value List, and the Row Source to "Blah Blah";"(REF) - Jackson";"Two Times";"(REF) - Tyson"
I put this in the Click event of a button:
If Me.RsnForInappropriateRef.Value Like "(REF)*" Then
Me.Check66 = True
Else
Me.Check66 = False
End If
it behaved exactly as expected. I then moved it to the AfterUpdate event of the combobox, and again it worked flawlessly. The only thing I can see is that in your example, the combobox does not have the same name as your sub (ReasonForInappriopriateReferral vs RsnForInappropriateRef). Are you sure your names are right?

Watin - How to set value of textarea (HTML editor)?

I'm trying to set the value of a textfield using the following code:
if (ie.TextField(Find.ById("testField")).Exists)
ie.TextField(Find.ById("testField")).Value = "Test";
The code passes without raising an error, however the textfield is not filled with the value.
I get an exception when I execute the following line:
ie.TextField(Find.ById("testField")).Focus()
The textarea is a tiny_mce editor and one of the html attributes is: style="display: none;"...
Any ideas how I can modify the value of such a field using Watin?
Thanks.
First tinymce is not a textarea. tinymce hides your textarea on initialization and creates a contenteditable iframe which is then used to allow text editing, styling aso...
Second if you want to write the editors content back to the hidden textarea you may do this using
tinymce.get('testField').triggerSave();.
Another way to set the value of your textarea is:
tinymce.get('testField').getDocumentById('testField').value = 'new value';
In case you want to write content directly to your tinymce editor you may choose on of the following
tinymce.get('testField').setContent('my_new_content'); // replaces the editors content
or
tinymce.get('testField').execCommand('mceInsertContent',false, 'my_content_to_be_added'); // adds the content at the carat postion
Here is a simple way to handle this using the Watin Eval function:
var js = "tinyMCE.get('body').setContent('" + bodyCont + "')";
var s = ie.Eval(js);
'body' needs to replaced with the id of the textarea that is hidden by tinymce - do a "view source" in your browser window to find this id.