UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> Vba - Clicking On An Internet Explorer Button With No Input Name    
 
   
guerillaunit
post Apr 10 2012, 03:49 PM
Post #1

UtterAccess Veteran
Posts: 354



Hi there,
I have a subfunction that opens up IE, goes to a webpage, and fills in the login fields. The "Login" button on the page does not have an input name associated with it. How would you click this button using VBA? I've tried calling the javascript function associated with the button, but get an access denied message
Go to the top of the page
 
+
 
Start new topic
Replies (1 - 4)
zocker
post Apr 11 2012, 06:50 AM
Post #2

Utterly Eccentric and Moderator
Posts: 3,663
From: Bristol / Ipswich / Spain



Greetings! This is not a highly recommended solution as it is a one way process, the called application cannot send back info..like if the actions have been successful. Use SendKeys Which have the effect of sending keystrokes to the 'outside' application, in this case you'd probably need Tab one or more times to get to Submit buton, then Enter. You'll need to look in the help files for the relevant key codes.



HTH



Zocker
Go to the top of the page
 
+
alv
post Apr 11 2012, 10:11 AM
Post #3

UtterAccess Addict
Posts: 110



the code i uses the Type associated with the login button, i did not write this code, hope this helps ( error processing removed):

CODE
Function Login2()
1   DoEvents
2   surl = [Forms]![Admin_ACCESS]![Combo51] ' webpage to log into
3   sUserID = [Forms]![Admin_ACCESS]![UserName] ' <- your ID goes here
4   sPassword = [Forms]![Admin_ACCESS]![Text61] ' <- your password goes here

5   Dim oIExplorer: Set oIExplorer = CreateObject("InternetExplorer.Application")
6   oIExplorer.Visible = 1
7   oIExplorer.Navigate surl

8   Do: Loop Until oIExplorer.ReadyState = READYSTATE_COMPLETE

9   Set objCollection = oIExplorer.Document.getElementsByTagName("input")

10    i = 0
11      While i < objCollection.Length
12          If objCollection(i).Name = "user" Then
13              objCollection(i).Value = sUserID
14          End If
15          If objCollection(i).Name = "password" Then
16              objCollection(i).Value = sPassword
17          End If
18              If objCollection(i).Type = "submit" Then
                ' "Search" button is found
19                Set objElement = objCollection(i)
20             End If
21             i = i + 1
22  Wend
23  objElement.Click
24  Set oIExplorer = Nothing
25  Set objElement = Nothing
26  Set objCollection = Nothing

End Function


This post has been edited by alv: Apr 11 2012, 10:12 AM
Go to the top of the page
 
+
guerillaunit
post Apr 12 2012, 02:16 PM
Post #4

UtterAccess Veteran
Posts: 354



hey alv,
your method works great. just to confirm, "objcollection" is essentially an array that stores "input" values. we then call a loop that checks every one of the objects in this array for the submit button. is this the correct description of what the code is doing?
Go to the top of the page
 
+
alv
post Apr 12 2012, 02:26 PM
Post #5

UtterAccess Addict
Posts: 110



sort of,it is not storing anything. objcollection is avariable for the inputs in a webpage you have loaded in IE. the code loops through the collection of inputs to find the ones we are looking for with .### depening on type. i did steal this code so i am not 100% but when i coded it i usual look at the source code and look the input needed. this can be difficult sometimes.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 21st May 2013 - 06:41 PM