I hope I don't confuse ya further... but I interact with 9.0, I will post the code I use.. it will 3 different sets of code. The first is the code that opens IE, navigates to the website, grabs creds from a table and passes them to IE.
Code:
Sub AuthData()
Dim aDa As InternetExplorer
Dim User, Pass As String
On Error Resume Next
' This is where creds are stored.
User = DLookup("[chrWebuser]", "tblWebCreds", "chrWebTools='Network Credentials'")
Pass = DLookup("[chrWebpass]", "tblWebCreds", "chrWebTools='Network Credentials'")
If Err.Number = 94 Then
MsgBox "Username or Password is missing", , "LIFT MESSAGE"
DoCmd.OpenForm "frmWebCreds"
Exit Sub
End If
Set aDa = Login("Website we are going to", True)
' I will attach another code window for SleepIE
Call SleepIE(aDa)
'P101_USERNAME is the spot we want to pass user into.
' P101_PASSWORD is the spot we want to pass pass into
aDa.Document.all.Item("P101_USERNAME").Value = User
aDa.Document.all.Item("P101_PASSWORD").Value = Pass
Call SleepIE(aDa)
aDa.Navigate "javascript:doSubmit('LOGIN');"
Call SleepIE(aDa)
''''''''''''credentials check if the page says Invalid login credentials on the body, it prompts a
'msg box thru java on the page.
If InStr(aDa.Document.Body.innertext, "Invalid Login Credentials") > 0 Then
aDa.Navigate "javascript:alert('Please Check your credentials.');"
Exit Sub
End If
' the button we want to click on the page.
aDa.Navigate "javascript:doSubmit('SUBMIT');"
End Sub
Okay, so thats the functioning bit of code. Below is going to be the SleepIE bit, and below that is going to be the internetexplorer bit.
Code:
Sub SleepIE(oIE As InternetExplorer)
Do While oIE.Busy: DoEvents: Loop
Do While oIE.ReadyState <> 4: DoEvents: Loop
Do While oIE.Document.ReadyState <> "complete": DoEvents: Loop
End Sub
Below is the IE part, it has a built in check for security certificate, this can be ignored if not needed but it should not harm anything.
Code:
Function Login(Address As String, AutoLog As Boolean) As InternetExplorer
Dim oIE As InternetExplorer
Set oIE = New InternetExplorer
oIE.Visible = True
oIE.Navigate Address
Call SleepIE(oIE)
If InStr(oIE.Document.Body.innertext, "There is a problem with this website's security certificate.") > 0 Then
oIE.Navigate "javascript:alert('Please resolve security certificate issue.');"
DoEvents
Do Until InStr(oIE.Document.Body.innertext, "Username") > 0
PauseApp 1
Loop
End If
If AutoLog = False Then MsgBox "Please login.", , "LIFT MESSAGE"
Set Login = oIE
End Function
I know its a lot of code, but it runs pretty solid. the entire process above takes 1.2 seconds
important to note, this code depends on a table to have stored credentials in it. This is easily replaced with a text box on your form, or simply hard coded. Just depends on your needs. I apologize if this is not what you are looking for.. but in the rare case I can help, I like to try.
- Additional note... if your webpage is using Java, these SleepIE things don't work very well. I actually had to use hard pauses... Code below.
Code:
Public Sub PauseApp(PauseInSeconds As Long)
Call AppSleep(PauseInSeconds * 1000)
' So when giving a javasite time to load, I just use a hardpause
appsleep .5 or something along those lines.
End Sub
I really hope this helps, I am having an issue with nulls that kind of has me at a stand still... any clarification is needed reply and I'm on it.
---- ANOTHER ADDITIONAL NOTE... the example above uses javascript, so the button click for submit looks like this ..
aDa.Navigate "javascript:doSubmit('SUBMIT');"
IF you are on a basic html site.... use this..
aDa.Document.all.Item("SUBMIT").Click
...