VBA webcontrol automation problem with inputfield - html

I'm an accountant and I develop a lot of automation to carry the repetitive task of my job. I've been fairly successful with most of them, but I got stuck with some code I can't find the solution to and probably it's just a simple thing I should already know.
So it's like this, I used to use selenium and make the code open an IE instance and navigate, login, fill multiple fields, select radio buttons etc. But I was using this with sendkeys function and Tab.
Now I reviewed all the code and implemented a webbrowser element to a userform and I'm using HTMLdoc to interact with the webpage, the objective of the app is to open the website, fill the invoice information then send and save the file, right now I'm able to login and navigate to the new invoice page.
The problem starts here, I use this code to get the text to the input fields on the webpage:
HTMLDoc.getElementsByName("dataInicio").Item(0).Value = Controlo_Arrendamento.txt_dataInicio
HTMLDoc.getElementsByName("dataFim").Item(0).Value = Controlo_Arrendamento.txt_dataFim
HTMLDoc.getElementsByName("dataRecebimento").Item(0).Value = Controlo_Arrendamento.txt_novoData.Text
HTMLDoc.getElementsByName("valor").Item(0).Value = Controlo_Arrendamento.txt_novoPago.Text & ",00"
HTMLDoc.getElementsByClassName("btn btn-sm btn-success").Item(0).Click
What happends is, when the submit button was pressed, the website gives me an error in every field, then I realized that when the data is inputed on the website normaly it automaticaly updates other elements on the webpage, it goes through some validation, so when my code inserts the values on the textbox it doesn't trigger, only by typing the values in...
So, I tried to dig everywhere for a solution, I watched the HTML elements and what changes when the value is valid and it's checked, tried implementing a .checked = true but no solution.
Anyone knows what I can do to get trough this?
I could send you the webpage but it needs a login and since it's a nacional finances website I'm afraid I can't share with you any login, but I will leave here the website in question, it may help figuring out what type of form i'm interacting with.
https://www.portaldasfinancas.gov.pt
Thanks in advance

Related

form submitting with onLoad input values instead of user inputted values when automated with VBA

Main Issue: When I submit a form using vba, the form's inputs' values change unexpectedly. I'm looking to see if there's an issue I don't know of with document.forms().submit in vba that might be related?
Code first, explanation follows:
htmlwindow.Document.getElementById("ReportNum_DropDownList").selectedIndex = 15
htmlwindow.Document.getElementById("ToMMYY_TextBox").Value = QtrMo & "/" & QtrYr
htmlwindow.Document.getElementById("FromMMYY_TextBox").Value = QtrMo_min2 & "/" & QtrYr
htmlwindow.Document.getElementById("ReportCols_DropDownList").selectedIndex = 2
htmlwindow.Document.getElementById("__EVENTTARGET").Value = "Display"
htmlwindow.Document.forms("Form1").submit
Using vba in excel I open IE, navigate to a login page and login, then arrive at "Reports" page which has "Form1", which has several elements.
When the Reports page loads, all of Form1's inputs have pre-loaded values from the last time I used the website. For instance input "FromMMYY_TextBox" is a text box that already reads "08/15" when the Reports page loads. I have several lines of code that update the inputs, including "FromMMYY_TextBox". Then I submit the form, and when it submits, it ignores the new values in the inputs and uses the pre-loaded values that populated the inputs upon originally loading the page. So if I made "FromMMYY_TextBox".Value = "09/15", it submits as "08/15" for some reason.
There is no "on_submit" in the element. I also tried to clear history/cookies/form submissions/passwords/etc from IE and do this, but when the Reports page loads, the inputs are still pre-populated. When I use ".click" on Form1's submit button, I have a more "intense" problem so that's ruled out as an option I think.
Is there anything strange about document.forms().submit that might cause this? Or should I try to see if I'm tripping some kind of validation code? I'm lost on what could cause this.
Edit: When I use ".click" on the Form's submit button, the form submits with the correct input values, but it will not display in the browser like it should. Instead it attempts to download the table as an excel file, which I do not want.
Edit2: I turned off auto-complete in IE and it did not help.

ColdFusion Cookie/Form Submission Loophole

Okay so here is my problem. I have developed a framework which does the following:
If, for example, you have four webpages... but you only want to allow users to reach the "4th" webpage after progressing through pages 1-3 sequentially - I have built this functionality (basically I set an encrypted cookie keeping track of what the user has completed thus allowing to know what they should be able to access). There are two parts of it:
1) If a page does NOT have a quiz, the user must only visit the webpages sequentially to be allowed to view the 4th page in the "progression".
2) However, if a page has a quiz on it, the user must successfully pass the quiz to go on to the next sequential page.
Now... Here is the real biggie... The last page will often be a web form which, obviously, I only want an individual to fill out and submit if they have reached the form by sequentially getting to that last page in the progression... BUT I found a flaw in the system. If someone were to go completely through the progression and fill the form out... they could delete their browser's "form data" and go "back" to the form and allow a friend to fill the form out. That would be detrimental to the system, and the users who will be navigating this progression are GOING to look for ways to get around going through it.
Some of the suggestions I will probably get will not be possible given the larger framework I am in, but rather than list all of the impossibilities I would like to see what you guys thought would be a way of getting around this issue?
P.S. This functionality is built in HTML and ColdFusion.
Thank you for any feedback, it is a great help!
EDIT:
Keep in mind the user must be able to back track any previous page they already completed.

Run VBA code whenever a tabbed form is reselected in Access

EDIT: For clarification, I'm talking in the below post about tabbed document browsing, not a Tab Control. However, if you're looking for roughly the same problem but regarding a Tab Control, Gord Thompson's answer is correct. Two answers for the price of one!
I've got an Access 2007 database that uses tabbed documents. I need to run some VBA code every time a user selects the form called "Reports", either via opening it or clicking on its tab if it's already open.
I could achieve much the same thing by closing it each time it's used and running the code on an OnLoad event, but ideally I'd like to keep it open so that users can keep the settings of the various drop down boxes, radio boxes etc that they've already set on "Reports".
I was hoping for an event that could run code on tab reselection, but neither of my guesses (OnCurrent and GotFocus) seem to work (OnCurrent works only when the form is opened, like OnLoad would).
Any ideas greatly appreciated - can't find what I'm looking for on Google, though I suspect that's because I don't know exactly what I'm looking for.
The .Value property of a TabControl returns the index (zero-based) of the current page. So, if I have a TabControl named TabCtl14 that contains two pages, FirstPage and SecondPage, then the code...
Private Sub TabCtl14_Click()
If Me.TabCtl14.Value = 1 Then
MsgBox "SecondPage was clicked."
End If
End Sub
...displays the MsgBox whenever I click the "SecondPage" tab in the TabControl.
Have found the answer I was looking for. It's the OnActivate event.

Creating "are you sure?" popup window by using html only

Assume I have a html from, and it contain some submit type. I want to create a "are you sure" popup window that will appear when user click submit button.
My question is that is there any way to create it by using "only" html, not using javascript or any other?
HTML only is possible, but not without a postback
Scenario that could work without javascript:
You have your form with submit button
User clicks (and submits) the form
You display another form with are you sure? form (that contains Yes and No buttons as well as hidden fields of the first form that will make it possible to do the action required on the original data
functionality that executes the action and goes back to whatever required.
This would be completely Javascript free, but it would require several postbacks.
This kind of thing is usually done on the client with a Javascript confirm() function (here's a simple example) or lately with a more user friendly modal dialog provided by many different client libraries or their plugins.
When to choose the script free version?
If you know your clients are going to be very basic ones (ie. vast majority of your users will access your application using clients like Opera Mini that's not able to run scripts at all). But in all other cases it's much better to do this using Javascript. It will be faster, easier to develop and much more user friendly. Not to mention that it will put less strain on your server as well since certain parts will execute on the client without the need of any server processing.
No, there isn't. Despite of the new features in HTML 5, HTML is still a markup language, not a programming language. In order to express dynamic behavior (such as an "are you sure?" box), you need to use a programming language.
Javascript would be the most obvious choice for this, but you could also do it with frameworks that can get you around writing Javascript by hand (for example ASP.NET).
Edit: Actually it appears that it would theoretically possible to do this with without Javascript or other frameworks. As I just learned, HTML 5 + CSS 3 seems to be turing complete. But this is hardly relevant to this question.
It's possible to ask for a confirmation, but it will not be in a "popup window". The creation of the "popup window" requires javascript/other language.
It will be:
Request (first form)
POST
Response (confirmation form)
POST
Response (outcome message)
You can create a form with all hidden elements containing the data from the first form and a "Yes" and "No" button below the "Are you sure?" text. You can use PHP sessions to avoid the hidden form elements. If there is a lot of data or confidential data or you do not want to re-validate the data from the second form, use sessions. Make sure you validate the data from either form before using it.
I know I'm like .. 10 years late. But for anyone still wondering I thought I could be of some help!
What I did for this exact problem was make sure I had multiple "divs" in my code. For me specifically, I had two main ones.
First, one whose id="main", and another whose id="popup" with the 'visible' property initially set to 'false' for the popup div.
Then, on whichever event you're looking for (button click for example) you'll simply set main.Visible = false and popup.Visible = true, then you could have more buttons in your popup (yes, no, cancel, confirm, etc.) which do the exact same thing, but in reverse!
The most important thing to make sure of is that you have the 'runat="server"' property in your divs so that you can access them in your CS code
Hope this was helpful! :)

URL form retrieval and submission via flash?

Totally new to flash and actionscript. What I want to do is retrieve a URL into a page (probably in a hidden frame or something), populate the form it contains with the correct fields (via my script), including possible data to upload, then submit it back. I guess an analogy use-case would be if I had a user choose a picture and then which site to upload it to (tinypic, flickr, etc), the script would download the main page, fill in the form data, attach the pic, and submit it. I saw a similar example in php somewhere, but I need to do it in flash.
I can probably get it eventually by myself, but if someone could point me in the right direction (keywords, functions to use/avoid, etc) I'd really appreciate it!
Rather than retrieving the form and trying to fill it out just use actionscript to directly post to the server side script.