Question : Access VBA to test for login or logout status ( If then Next)

Hello Experts,
I have had several questions on this site and yet to find a resolution that I could use. This I think will not be too hard to do.

I have an Access 2003 module that logs into a Customer's website to download daily data. My code actually works pretty good. However, if I am already logged into the site I get a Run-Time Error 91 Object Variable or With variable not set.

It is giving me this error because the code is looking for the Form to add the user name and password. When this is not found it gives me the error. I need some simple VBA that will test the condition of the login for that instanace of IE. If it is already logged in then proceed to the next step, if it is not logged in the it needs to login before proceeding to the same next step.

I think it should be pretty simple for an expert.(Which I am not!!) Here is my code.
If the user is not logged into the site then I need to pass the user name and password through IE into the forms and then proceed.

This line of code is the ultimate detigation.
    QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/")
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
Option Compare Database
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
 
Public Function SkpiUpdate()
 
Dim QPR As Object
Dim lnk As Object
Dim TimeOut As String
Dim frm As Object
Dim Start As Object
Dim Finish As Object
'Dim drp2 As Object
Dim drp1 As Object
Dim src1 As Object
Dim p1 As Variant
Dim objWB As Object
Dim objExc As Object
 
 
Set QPR = CreateObject("InternetExplorer.application")
 
    QPR.Visible = True
    
    QPR.navigate "https://www.portal.toyotasupplier.com/wps/myportal/"
    
  TimeOut = Now + TimeValue("00:00:20")  '-- wait maximum of 20 seconds
   Do While QPR.Busy Or QPR.readyState <> 4
      DoEvents
      If Now > TimeOut Then
        MsgBox "Time Out before Login"
        Exit Function
      End If
   Loop
 
   With QPR.Document.Forms("Login")
   .User.Value = "xxxxxxxx"
   .Password.Value = "xxxxxxx"
   .submit
   End With
 
   TimeOut = Now + TimeValue("00:00:40")  '-- wait maximum of 10 seconds
   Do While QPR.Busy Or QPR.readyState <> 4
      DoEvents
      If Now > TimeOut Then
         MsgBox "Time Out after Login"
         Exit Function
      End If
   Loop
    QPR.navigate ("https://www.portal.toyotasupplier.com/skpi/")

Answer : Access VBA to test for login or logout status ( If then Next)

i wrapped the login code in a for each object of qpr forms until object name = login...

works for me..

i borrowed one of yourother objects to test it.  be best to make a specific one just for this bit.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
 For Each drp1 In QPR.Document.Forms
 MsgBox drp1.Name
    If drp1.Name = "Login" Then
         With QPR.Document.Forms("Login")
        .User.Value = "xxxxxxxx"
        .Password.Value = "xxxxxxx"
        .submit
        End With
    End If
  Next drp1
Random Solutions  
 
programming4us programming4us