Link to home
Start Free TrialLog in
Avatar of thenelson
thenelson

asked on

select radio button in webbrowser control using vba

I have a webpage with the following code:
<label><input type="radio" name="patient_gender" value="patient_gender_m" id="patient_gender_value_patient_gender_m" />Male</label>
<label><input type="radio" name="patient_gender" value="patient_gender_f" id="patient_gender_value_patient_gender_f" />Female</label>

Open in new window

I would like to select the male or female radio button as appropriate.

What is the correct code to do this?

I have successfully filled input boxes on the page with code like:
Me.ocxWebBrowser.Document.Forms(0).patient_fname.Value = "Nelson"

Open in new window


These create the error "object doesn't support the property:
Me.ocxWebBrowser.Document.Forms(0).patient_gender_value_patient_gender_m.checked=true
Me.ocxWebBrowser.Document.Forms(0).patient_gender_value_patient_gender_m.click

Open in new window

Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Instead of true/false, try check / uncheck.

i am looking for exact syntax now.
Avatar of thenelson
thenelson

ASKER

Me.ocxWebBrowser.Document.All.patient_gender_value_patient_gender_m.checked=check
produces "object doesn't support this property"
I was hopping this will work:

Me.ocxWebBrowser.Document.All.patient_gender_value_patient_gender_m.checked

with no = True
Me.ocxWebBrowser.Document.All.patient_gender_value_patient_gender_m.checked
produces "object doesn't support this property"

not sure what you mean by:
with no = True
I found my problem. The correct syntax is:
       Me.ocxWebBrowser.Document.Forms(0).patient_gender_value_patient_gender_m.Click
but the webpage I am trying to interface with changes the name of the gender radio button depending upon which form is called up. I some cases it is:
     patient_gender_value_patient_gender_m
while other forms (for the same page), its:
     gender_value_gender_m

The other field id's remain the same between the forms.
ASKER CERTIFIED SOLUTION
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, the Click property is used. I was running into problems because the website pulls up different forms for different insurance companies. Although the ID's for the textboxes stay the same from form to form, the gender radio buttons ID's change for different forms. So sometimes the Click property worked and sometimes it didn't.

Thanks for your input.
You are welcome. Thank you for the points.

Also for the record, I called event while I should have said method.

I wonder if it will work with () like:

Me.ocxWebBrowser.Document.Forms(0).patient_gender_value_patient_gender_m.Click()