How to select dropdown lists with no id - vba

I've been researching this for the last couple days but haven't found a solution yet. Any help would be greatly appreciated.
I'm using VBA to put a push button on an Excel spreadsheet which will open an Internet Explorer window, log people into a particular site, search for a particular "case" (webform) on the site, fill in the values the way the user specified on the sheet, and then submit the form. Everything works except the form fields that are drop down lists. When I run it, it fills in the values I want in those fields but it seems like it's not actually selecting them from the list, just overwriting what's displayed there, because when it clicks submit an error window pops up saying to fill in those drop down fields.
From my research I've seen various solutions for how to search a drop down list and set it to the selected index once it's located the text I want, but my problem is that I haven't had luck selecting the drop down list at all. If you look at the screenshot below, that shows one of the fields as it looks in Internet Explorer's dev tools:
The highlighted portion is the id number I use to paste in my text (what I'm doing right now that isn't working) but the line below it with class ns-dropdown seems like it might be what I really want to access, but that line doesn't have an id.
Here's the relevant portion of my code:
Dim IE As Object
Dim IEForm As HTMLDocument
Set IEForm = IE.Document
With IEForm
.getElementById("custevent_crc_code_fs").innerText = Sheet1.Cells(9, 3) 'CRC Code
.getElementById("inpt_status4").innerText = Sheet1.Cells(8, 3) 'Status
.getElementById("inpt_custevent95").innerText = Sheet1.Cells(11, 3) 'Department
.getElementById("inpt_custevent426").innerText = Sheet1.Cells(10, 3) 'Case Origin
.getElementById("inpt_custevent447").innerText = Sheet1.Cells(6, 3) 'Created By
.getElementById("inpt_custevent1188").innerText = Sheet1.Cells(7, 3) 'Contact Reason
.getElementById("btn_multibutton_submitter").Click
End With
Let me know if you need any more information. I've been wrestling with this for a while and am trying not to flood you with too much extraneous info about things I've tried.

Related

Search text file and put matching results in listbox

I have a VB.NET project in which there is a form where there is a TextBox control, a ListBox control and an external text file that contains a list of outlook folder paths for client emails.
Essentially, the user enters into the text box the name of a client and/or their unique reference number, presses the search button (yes - I know I could make the results appear as they type, I want a button!) and it comes up with the matching results for the company name or serial number that are in the text file and puts them in the list box, with the full path of the outlook email folder.
For example:
If I put into the textbox: "06967759-274D-40B2-A3EB-D7F9E73727D7"
It would put the following result into the listbox:
"EIS Admin\Contacts{06967759-274D-40B2-A3EB-D7F9E73727D7}"
And the user can then go to that folder and find the email(s).
I have gone through several revisions both of my own code and code pasted from online with people having the same issue, only to have Visual Studio throw no errors, run the code and have no luck, with it doing nothing but clearing the list box, and not showing matching results of any kind.
I understand this may be a repeat question but I am extremely confused, can't get anything to work and need some help regarding my issue.
Here is the current code (from online - not mine):
lbx_OFL_Results.Items.Clear()
Dim i As Integer
For i = 0 To lbx_OFL_Results.Items.Count - 1
If i > lbx_OFL_Results.Items.Count - 1 Then Exit For
If Not lbx_OFL_Results.Items(i).Contains(tbx_FindText.Text) Then
lbx_OFL_Results.Items.Remove(lbx_OFL_Results.Items(i))
i -= 1
End If
Next
The list box is called "lbx_OFL_Results"
The textbox is called "tbx_FindText"
I start by clearing the list box of all items (when the form loads, it fills the list box will all lines of the text file, so I need to clear it).
Form Load Event Code:
Dim lines1() As String = IO.File.ReadAllLines("C:\ProgramData\WPSECHELPER\.data\Outlook Folder Wizard\outlookfolders.txt")
lbx_OFL_Results.Items.AddRange(lines1)
For the rest of the code it seems to be doing some form of a 'sort search' then removing any excess results.
If anyone can suggest edits to my code, or new code then that would be sublime.
Thanks.
Thanks to #Jimi for the answer.
Code:
listbox.Items.Clear()
listbox.BeginUpdate()
For i as Integer = 0 To lines1().Length - 1
If lines1(i).Contains(searchbox.Text) Then
listbox.Items.Add(lines1(i))
End If
Next
listbox.EndUpdate()
I have another question which solves how to make this search non case-sensitive. It can be found here.

Excel-VBA UserForm ListBox - How can I Highlight option without Selecting

Nutshell:
What is the equivalent to Me.ListBox1.Selected(2) = True but for highlighting instead of Selecting?? (Highlight might be the wrong word but I'm sure I've seen that before in this context - the outline box around an option instead of actually selecting it)
** Tried **
Me.ListBox1.ListIndex = 2
doesn't do anything either.
With Me.ListBox1
saveVal = .List(0)
.Value = ""
.Value = saveVal
End With
Gives me an error saying "Invalid Property Value"
Background:
Why do I need to click twice on some items/boxes?
I have a userform with several ListBox which are populated by adding items one by one, which works fine.
The ListBox settings have been changed to MultiSelect = 1 - fmMultiSelectMulti and ListStyle = 1 - fmListStyleOption
The issue is when trying to select an option on some boxes for the first time, it just highlights it without selecting it, while on other boxes and other tries it may or may not select an option straight away. It doesn't seem to be the same culprits and is a bit random - does it have something to do with where I'm clicking on the option? On the item text instead of the item box? Why does it work on some and not others?
After I've selected one option in a box, it then allows me to select any other with a single click which is the desired behaviour.
I found a link where someone had suggested this behaviour was because of a corrupted workbook, but I don't think it's that. I just created a new book with 1 listbox in a userform, changed to desired settings, copied the listbox 6 times, put the listsource as rand() in columns A:G and I'm still getting the same issue.
Edit: My plan is to "highlight" the top option on each box so that the first click on a box has no option other than to select (because something is already highlighted)...
The trick to tackling my INITIAL problem seems to have been after populating each list to set .ListIndex = 0 but this only worked after using .SetFocus
Solved! (For now, I think)
Even though this doesn't highlight anything it allows me to select something first time without fail.

PCOMM gettext is pulling invisible information

I've had a randomly recurring issue where I can use gettext to pull information just fine from a page on a PCOMM (IBM Personal Communicator) screen, then when I go to the next screen it will pull that SAME information, despite appearing visually blank.
I can't paste screenshots for InfoSec reasons... But here's the gist:
Dim ps As New AutPS
Dim oia As New AutOIA
Page 1: ps.GetText(15,31,7) = 1800.00 (I can see this value on the screen.)
Go to next page, wait for oia.InputInhibited = 0 And ps.Ready
Page 2: ps.GetText(15,31,7) = 1800.00 (Screen in this position appears blank.)
This issue is not isolated, and is repeatable with a specific account number.
Found a solution!
The key lies with using the ps.autECLFieldList. This object can detect when a given field (located using FindFieldByRowCol) is displayed or not, so when used in tandem with our getText, we can make sure that we're only retrieving information from a visible field.
Dim fl As Object = ps.autECLFieldList
fl.refresh() 'Good practice to make sure the Field List is up to date
If fl.FindFieldByRowCol(15, 31).display Then
Amount = ps.GetText(15, 31, 7)
End If

In Microsoft Publisher VBA, how to access selected page?

In Publisher, not VBA, I use the navigation pane to select page 5. Now, the work I do manually will apply to page 5. However, now I want to run a macro I wrote which will import, resize, label, etc. a batch of images. How do I make my macro recognize that I want those images imported onto page 5 (my current working page)?
I wrote my macro hardwired to page 2 (because I couldn't answer the above question):
set pg = activedocument.pages(2)
I envisioned something like (but this doesn't work, of course):
set pg = activedocument.selected.page
Similarly, after my macro runs, and it adds three new pages, I want the selected/active page to be the last page I added (e.g., page 9). How to do that? Again, I envisioned something like:
activedocument.pages(9).select
Much thanks.
The property that you found (helping me out, so thanks!) is for both getting and setting, but the trick is that you have to set it to a page, rather than trying to set it to a PageIndex ("ActivePage = 2")
ActiveDocument.ActiveView.ActivePage = yourPage;
For instance, you could go to the next page with:
pubApp.ActiveDocument.ActiveView.ActivePage = pubApp.ActiveDocument.Pages[pubApp.ActiveDocument.ActiveView.ActivePage.PageIndex+1];
...Just realised that you're asking about VBA rather than C#, so here are some VBA examples just for you:
GoToNextPage()
ActiveDocument.ActiveView.ActivePage = ActiveDocument.Pages(ActiveDocument.ActiveView.ActivePage.PageIndex + 1)
End Sub
GoToPageTwo()
ActiveDocument.ActiveView.ActivePage = ActiveDocument.Pages(2)
End Sub
Question 1 is answered:
Set p = ActiveDocument.ActiveView.ActivePage
Question 2 remains:
How do I use vba to make active a new particular page?
(i.e., i could use VBA such that the above would return to me a different page for "p"?)
For a shape, I can say: "my_shape.select"; how do I do that for a page?

VB in Access: Combo Box Values are not visible in form view but are visible through Debug.Print

Code in Form onLoad:
country_combo.RowSourceType = "Value List"
Code in a reset function:
Dim lListIndex As Long
With Me.country_combo
For lListIndex = .ListCount - 1 To 0 Step -1
.RemoveItem (lListIndex)
Next lListIndex<br/>
End With
Code to populate country combo:
*For n = 1 To numCountries*
*countryCombo.AddItem (countryRS.Fields("countryName"))*
*countryRS.MoveNext*
*Next n*
I'm having a problem that occurs AFTER the code to populate the country combobox runs. The values are there as I can run Debug.Print(countryCombo.Value) and it prints out the name of the selected country, but I can't see the values in the combobox at all. They're invisible, and as far as I know there is no visiblity property for specific items, unless I'm completely mistaken.
comboBoxError.png http://img110.imageshack.us/my.php?image=comboboxerror.png
I think you should probably use Access's GUI tools to do what you're looking for. In design mode, click on the field you are trying to populate, then click the "lookup" tab. You can then specify a table to populate the field with and your forms should automaticly update as well.
I've also seen what you describe here - as far as I can tell, it's a bug within Access (I was using 2007) that only occurs when you programatically mess with the contents of a combo box. It does not happen every time. The issue corrects itself if you highlight the text that is in the combo box.
I am experiencing a similar issue with Access 2003. Based on the selection of one combo box, the row source of a listbox is set to an SQL string Basically a SELECT DISTINCT [MyField_Selected] FROM MyTable. For some fields the values are visible in the list box and others it is not. The values are there however as I can access them via code. To make it more interesting it works fine in Access 2007.
Just found the resolution on another forum. Check the format property of the field(s) in question on the table. In my case, when Access 2007 created the table, it put an # format in there. I removed that and all works great!