Results 1 to 13 of 13
  1. #1
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186

    Making connection to email account

    Hello everyone,

    I am making an event to connect to a web mail as a License of my access app, if the password is still working or live the app should be opening, otherwise it should show "license time is over"

    I have the event but what I don't consider is the logic of get in or rejected from the account. The code works good to fill the fields on the website but I don't know how add for the logic of the incorrect password

    Also the error message (KeyErr: on my code) is also shown even there is not an error

    I highly appreciate the help



    Code:
    Option Compare Database
    
    
    Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" _
                (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    
    Global Const SW_MAXIMIZE = 3
    Global Const SW_SHOWMINIMIZED = 2
    Global Const SW_SHOWNORMAL = 1
    
    Sub Key()
    
    
    On Error GoTo KeyErr
    
    Dim email As String
    Dim Password As String
    
    email = DLookup("[Usermail]", "[License_tbl]")
    Password = DLookup("[UserPassword]", "[License_tbl]")
    
    ' open IE, navigate to the desired page and loop until fully loaded
        Set IE = CreateObject("InternetExplorer.Application")
           my_url = "https://mail.ionos.mx/"
            
    IE.Visible = 1
    'apiShowWindow IE.hwnd, SW_MAXIMIZE
    apiShowWindow IE.hwnd, SW_SHOWMINIMIZED
    
        With IE
            .Visible = True
            .Navigate my_url
    
        Do Until Not IE.Busy And IE.ReadyState = 4
            DoEvents
        Loop
    
        End With
    
    ' Input the userid and password
        IE.Document.getElementById("login-form-user").Value = email
        IE.Document.getElementById("login-form-password").Value = Password
    
     
    ' Click the "login" button
        'IE.Document.all.Item("Submit").Click // Este metodo tambien funciona
        IE.Document.getElementsByTagName("button")(0).Click
        Do Until Not IE.Busy And IE.ReadyState = 4
            DoEvents
        Loop
    
        IE.Quit
        
        MsgBox "Succesful get in", vbInformation, "System Example"
            
    'This part is also showing the message despite the previous message has been shown, I'm not sure why
    KeyErr:
    MsgBox "Validate your connection or license due date", vbExclamation, System Example"
    Exit Sub
    
    End Sub
    Thanks in advance for the help!!!!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,272
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    You need to add an Exit Sub after the first msgbox to stop the code from showing the error message. As for the logic for the incorrect password it depends on what the web page returns. Once you click the Submit button you need to check the page again for whatever the element indicates a good or bad password.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi
    Thanks for the tip of the Exit Sub

    About the page this is what it's shown if the password is wrong

    Click image for larger version. 

Name:	error login.jpg 
Views:	29 
Size:	44.6 KB 
ID:	49339

    with inspect element this is the code for this part

    Code:
    <div id="login-error" class="notificaiton-wrap" style="display: block;">
    <dl class="notification notification-danger" 
    data-prio="50"><dt class="notification-heading">Se ha producido un error.</dt>
    <dd class="notification-description">La contraseña introducida no es correcta o no existe la dirección de e-mail.
    </dd>
    </dl>
    </div>
    any recommendation?

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    I don't have much experience with automating IE but what happens if you try something like this:
    Code:
     If InStr(IE.Document.getElementById("notification-description").Value, "La contraseña introducida no es correcta o no existe")> 0 Then
    'wrong password - display custom message and exit
    Else
    'login OK
    End If
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi

    I state the code like this but it doesn't work, in fact it show an error

    Code:
    Sub Key()
    
    
    'On Error GoTo KeyErr
    
    
    Dim email As String
    Dim Password As String
    
    
    email = DLookup("[Usermail]", "[License_tbl]")
    Password = DLookup("[UserPassword]", "[License_tbl]")
    
    
    ' open IE, navigate to the desired page and loop until fully loaded
        Set IE = CreateObject("InternetExplorer.Application")
        my_url = "https://mail.ionos.mx/"
            
    IE.Visible = 1
    'apiShowWindow IE.hwnd, SW_MAXIMIZE
    apiShowWindow IE.hwnd, SW_SHOWMINIMIZED
    
    
        With IE
            .Visible = True
            .Navigate my_url
    
    
        Do Until Not IE.Busy And IE.ReadyState = 4
            DoEvents
        Loop
    
    
        End With
    
    
    ' Input the userid and password
        IE.Document.getElementById("login-form-user").Value = email
        IE.Document.getElementById("login-form-password").Value = Password
     
    ' Click the "login" button
        
        IE.Document.getElementsByTagName("button")(0).Click
        Do Until Not IE.Busy And IE.ReadyState = 4
            DoEvents
        Loop
        
        If InStr(IE.Document.getElementById("notification-description").Value, "La contraseña introducida no es correcta o no existe") > 0 Then
        'wrong password - display custom message and exit
        
        MsgBox "License expired", vbInformation, "Q-Sys Quality Management Tool"
        
        Else
        'login OK
          MsgBox "License on time", vbInformation, "Q-Sys Quality Management Tool"
        
        End If
        
        'IE.Quit
        
       ' MsgBox "Conexion exitosa", vbInformation, "Q-Sys Quality Management Tool"
        
        Exit Sub
        
    'KeyErr:
    
    
        'IE.Quit
        'MsgBox "Valide su conexión a internet", vbExclamation, "Q-Sys Quality Management Tool"
        'Exit Sub
       
    End Sub

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    And the error is.....
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    sorry
    the debugger marks it here

    If InStr(IE.Document.getElementById("notification-description").Value, "La contraseña introducida no es correcta o no existe") > 0 Then

    error 424 object required

  9. #9
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186

    Connectivitytoemail

    Hello everyone,

    I enclosed the example with the components, I created an email and a password that gets in the webmail site
    If you can take a look on this I will highly appreciate this

    Conectivitytoemail app.zip

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,272
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Here it is, sorry that took a while.

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi Vlad!!!

    I highly appreciate the help!!! You really help me so much with this solution!!!

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235


    Happy holidays!
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Email Out Account Depending on PC Name
    By DMT Dave in forum Access
    Replies: 8
    Last Post: 06-06-2021, 01:28 AM
  2. Replies: 2
    Last Post: 06-27-2018, 02:27 PM
  3. Replies: 1
    Last Post: 06-25-2018, 04:15 PM
  4. Replies: 2
    Last Post: 06-20-2018, 11:29 AM
  5. Remote Desktop Connection Broker connection string
    By Philosophaie in forum Access
    Replies: 1
    Last Post: 09-14-2015, 03:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums