Thanks!
I don't think it was an issue with the page not having loaded first. I was
waiting until it finished loading before logging in. (I'm logging in with a
button, not automatically when the page is loaded.)
Also, with the Access 2010 web browser control (not the ActiveX one; but the
one that's built into Access 2010), you would reference the object in the
control (sort of like the !Subform.Form syntax). So it would be:
htm = WebBrowser1.Object.Document
In any case, I tried it with Forms(0).Submit, Forms(1).Submit, etc. Forms(0)
was still the search button; but, what do ya know - Forms(1) was the Login
button! So that worked great. Below is my final code, using the embedded
browser. Thanks for all your help!
Dim UserN As Variant
Dim PW As Variant
With Me.wbrAccount.Object
Do While .Busy
Loop
Set UserN = .Document.getElementsByName("username")
If Not UserN Is Nothing Then
UserN(0).Value = Me.Username
End If
Do While .Busy
Loop
Set PW = .Document.getElementsByName("password")
If Not PW Is Nothing Then
PW(0).Value = Me.Password
End If
Do While .Busy
Loop
.Document.Forms(1).submit
End With
You need to do this after the web page has finished loading. In the
vba editor you'd select the WebBrowser control from the top left combo
box (in this case WebBrowser1), then in the combo box to the right
select the DocumentComplete event. It will paste in a stub that looks
like this:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As
Variant)
End Sub
then:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As
Variant)
Set htm = WebBrowser1.Document
htm.Forms(0).submit
End Sub
I'm pretty sure this is the right way to do it but it also depends on
if there are multiple forms on the page (and I may be forgetting
something else).
So if there are multiple forms on the page you'd need to change
Forms(0) to Forms(1) etc. You can check this in the browser by looking
at the page source and counting the number of forms.
So every time the document completes it will hit the submit function
for the first form. So you'd probably check which page it's on before
it does that:
Private Sub WebBrowser0_DocumentComplete(ByVal pDisp As Object, URL As
Variant)
Dim htm As HTMLDocument
Set htm = WebBrowser0.Document
If htm.URL = "
http://www.First Page" Then
htm.Forms(0).submit
End If
End Sub