Unlock locked form fields with VBA (1 Viewer)

wackywoo105

Registered User.
Local time
Today, 01:38
Joined
Mar 14, 2014
Messages
203
I’m trying to complete a form where some elements are locked until others have been completed. When doing this manually just the act of typing something into the required fields unlocks the corresponding controls.

For some reason entering the data like this doesn’t unlock the locked field:
Code:
IE.Document.getElementById("txtPrescriptionRightDistanceCyl").Value = Right(RECyl, 5)

So, I’ve tried sendkeys, which works but is messy and runs the risk the user clicks another window before it executes:
Code:
IE.Document.getElementById("txtPrescriptionRightDistanceCyl").Select
SendKeys "{ENTER}", True

I also tried :
Code:
IE.Document.parentWindow.execScript "OnChangeEvent(this)"
After all data has been entered into unlocked boxes, but it doesn’t work.

Can anyone help me unlock these controls? The green arrows show the controls and what they unlock, which I have included in the locked and unlocked states. I've put the html for the fields below.

Screenshot 2023-11-24 08.44.54.jpg


+/- while locked
Code:
<input name="outcomemodel.PMPrescriptionRightDistanceCyl" disabled="disabled" class="form-control margin-left-10 w38 text-box single-line" id="txtPMPrescriptionRightDistanceCyl" type="text" maxlength="1" placeholder="+/-" value="" autocomplete="off">

CYL
Code:
<input name="outcomemodel.PrescriptionRightDistanceCyl" class="form-control w68 margin-left-5 text-box single-line" id="txtPrescriptionRightDistanceCyl" onchange="OnChangeEvent(this)" type="text" maxlength="5" placeholder="00.00" value="" autocomplete="off" data-val="true" data-val-number="The field PrescriptionRightDistanceCyl must be a number.">

+/- after unlocked
Code:
<input name="outcomemodel.PMPrescriptionRightDistanceCyl" class="form-control margin-left-10 w38 text-box single-line" id="txtPMPrescriptionRightDistanceCyl" type="text" maxlength="1" placeholder="+/-" value="" autocomplete="off">


Reading Voucher Type while locked
Code:
<select name="outcomemodel.SecondVoucherTypeCode" disabled="" class="form-control" id="outcomemodel_SecondVoucherTypeCode"><option value="0">Please Select</option>
<option value="920000650">A</option>
<option value="920000651">B</option>
<option value="920000652">C</option>
<option value="920000653">D</option>
</select>

Add
Code:
<input name="outcomemodel.PrescriptionRightNearSph" class="form-control w68 margin-left-5 margin-left-18 ipad-radio-btn-margin text-box single-line" id="txtPrescriptionRightNearSph" onchange="OnChangeEvent(this)" type="text" maxlength="5" placeholder="00.00" value="" autocomplete="off" data-val="true" data-val-number="The field PrescriptionRightNearSph must be a number.">

Reading Voucher Type after unlocked
Code:
<select name="outcomemodel.SecondVoucherTypeCode" class="form-control" id="outcomemodel_SecondVoucherTypeCode"><option value="0">Please Select</option>
<option value="920000650">A</option>
<option value="920000651">B</option>
<option value="920000652">C</option>
<option value="920000653">D</option>
</select>
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 09:38
Joined
Feb 19, 2013
Messages
16,612
Is this a normal form or a form in a web control?

if a normal form, why not use conditional formatting to disable a control when required conditions are not met?
 

sonic8

AWF VIP
Local time
Today, 10:38
Joined
Oct 27, 2015
Messages
998
I’m trying to complete a form where some elements are locked until others have been completed. When doing this manually just the act of typing something into the required fields unlocks the corresponding controls.
You should explicitly mention that this about a HTML form in a web browser control, not about an Access form.

I'm afraid there is no generic solution to this problem. You'll have to analyze the JavaScript code of the web page to find the right approach to unlock those controls.

You could try to just remove the disabled attribute of the input controls with some custom JavaScript in the webbrowser. However, this is a very brute force approach and it might have undesired side effects.
 

sonic8

AWF VIP
Local time
Today, 10:38
Joined
Oct 27, 2015
Messages
998
I also tried :

Code:
IE.Document.parentWindow.execScript "OnChangeEvent(this)"

After all data has been entered into unlocked boxes, but it doesn’t work.
This is the right direction.
However, you need to pay attention to what this refers to in the context.
I believe with your script snippet it will refer to the document as a whole, while inside the input tags it refers to the individual input element.
 

wackywoo105

Registered User.
Local time
Today, 01:38
Joined
Mar 14, 2014
Messages
203
Sorry I should have said this is a website form.

I've added
Code:
appactivate IE
before the sendkeys and it appears to be working well.

I wondered if could directly edit the html to remove the 'disabled="disabled"' from the locked controls, but don't know how to do this. Or how can I make my code snippet work for the relevant input tags?
 
Last edited:

cheekybuddha

AWF VIP
Local time
Today, 09:38
Joined
Jul 21, 2014
Messages
2,280
Hi, you have been asking a lot of questions regarding completing this webform recently.

From some of your posts, it appears to be an NHS website/intranet site.

Are you working within the NHS?

If so, perhaps get on to the developers to see if they offer an API for performing the operations.

It might be quite possible to do everything you need using HTTP requests and bypass the site entirely.
 

Edgar_

Active member
Local time
Today, 03:38
Joined
Jul 8, 2023
Messages
430
In another thread of yours I wrote a lenghty post warning you that just entering data programmatically won't fire events associated to that element, read this again
Post in thread 'Help filling in a web form from access.' https://www.access-programmers.co.u...in-a-web-form-from-access.329457/post-1897576

You need to fire the events, there are 2 possible snippets there that you can use. As mentioned there, it is not adviced to do unintended things like bypassing the form and directly call its functions because you don't know if the developer accounted for that type of form filling. Unless you're trying to cheat their system, fill the form mimicking what a user would do.
 

Users who are viewing this thread

Top Bottom