Solved

MS access open web page

Posted on 2012-03-29
17
657 Views
Last Modified: 2012-06-27
Hi
I have a MS access form that have client name and country, that i need to press a function button to open a web page and press "user login" button and insert the user name and password and press the "login" button "automatically"
Wait till the web open the search screen appears.
After that I need the same function to copy the client name and country from the MS form to web search page and insert them into text box "name" and other text box "country" then
Press the "start search" button.
Web will start searching  and provide the result on the screen.
The function will press the "print" button and a new web page will open showing the result that I need to save it in pdf format.
and close.
0
Comment
Question by:HKH1967
  • 8
  • 7
  • 2
17 Comments
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 37781568
You may be able to adapt this to get to the page you want.
As for PDF printing, download PDFCreator - this comes with some VBA options that must be able to be used between access, IE and PDF

Private Sub IE_Autiomation()
    Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
 
    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
 
    ' You can uncoment Next line To see form results
    IE.Visible = False
 
    ' Send the form data To URL As POST binary request
    IE.Navigate "http://www.website.com/"
 
 
    ' Wait while IE loading...
    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
 
    ' Find 2 input tags:
    '   1. Text field
    '   <input type="text" class="textfield" name="username" size="24" value="" />
    '
    '   2. Button
    '   <input type="submit" class="button" value="" />
 
    Set objCollection = IE.document.getElementsByTagName("input")
 
    i = 0
    While i < objCollection.Length
        If objCollection(i).Name = "username" Then
 
            ' Set text for search
            objCollection(i).Value = "JohnSmith"
 
        Else
            If objCollection(i).Type = "submit" And _
               objCollection(i).Name = "" Then
 
                ' "login" button is found
                Set objElement = objCollection(i)
 
            End If
        End If
        i = i + 1
    Wend
    objElement.Click    ' click button to search
    
    ' Wait while IE re-loading...
    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
 
    ' Show IE
    IE.Visible = True
 
    ' Clean up
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing

End Sub

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37781737
Just note here that this is really a request for a "complete Project"...
Not really a single question requiring a straightforward answer...
The format of this site is, one question one answer...
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37781751
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:HKH1967
ID: 37783134
Hi INHOUSERES
once I run the procedure i get the attached errors.
and the web is not opening,, thanks
ie-error1.png
ie-error2.png
0
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 37786066
change all the lines that say "Application.wait..." to "DoEvents"

The reason you're getting the second error is because of the first.

If you want to see IE running in the background, change "IE.Visible = False" to "IE.Visible = True".

Hope this helps.

To provide more help, I will need to see the page you're trying to access.
0
 

Author Comment

by:HKH1967
ID: 37786930
INHOUSERES:
the link is
http://www.world-check.com/
0
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 37787023
Try this:

I've tested this and it works ok.
Don't forget to change "JohnSmith" to an actual username and "qwerty" to an actual password at the top of the code

        Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
 
    myUsername = "JohnSmith"
    myPassword = "qwerty"
 
    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
 
    ' You can uncoment Next line To see form results
    IE.Visible = True
 
    ' Send the form data To URL As POST binary request
    IE.Navigate "http://www.world-check.com/"
    
    ' Wait while IE loading...
    Do While IE.Busy
        DoEvents
    Loop
    
    ' get all the clickable links
    Set objCollection = IE.Document.getElementsByTagName("a")
    
    ' find the one called "user login" and click it.
    While i < objCollection.Length
        If objCollection(i).href = "llogin" Then
            objCollection(0).Click
            
            ' Wait while IE loading...
            Do While IE.Busy
                DoEvents
            Loop
            
            'skip to the part that logs you in
            GoTo Loggingin
        End If
    Wend
    
Loggingin:
    Set objCollection = IE.Document.getElementsByTagName("input")
 
    i = 0
    While i < objCollection.Length
        If objCollection(i).Name = myUsername Then
 
            ' Set text for search
            objCollection(i).Value = "JohnSmith"
 
        ElseIf objCollection(i).Name = myPassword Then
 
            ' Set text for search
            objCollection(i).Value = "qwerty"
 
        Else

            If objCollection(i).Name = "submitted" Then

                ' "login" button is found
                Set objElement = objCollection(i)
 
            End If
        End If
        i = i + 1
    Wend
    objElement.Click    ' click button to search
    
    ' Wait while IE re-loading...
    Do While IE.Busy
        DoEvents
    Loop
    
    ' Clean up
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing

Open in new window

0
 

Author Comment

by:HKH1967
ID: 37787173
INHOUSERES:
I try it and it open the web and does not click the user login textbox and stop.
once close the web page it gives the attached error.
err3.png
0
 
LVL 5

Accepted Solution

by:
INHOUSERES earned 500 total points
ID: 37787245
So very sorry! Pasted and older version of the code!

    Dim i As Long
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
 
    myUsername = "JohnSmith"
    myPassword = "qwerty"
 
    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
    
    ' You can uncoment Next line To see form results
    IE.Visible = True
 
    ' Send the form data To URL As POST binary request
    IE.Navigate "http://www.world-check.com/"
    
    ' Wait while IE loading...
    Do While IE.Busy
        DoEvents
    Loop

    ' get all the clickable links
    Set objCollection = IE.Document.getElementsByTagName("a")
    
    ' find the one called "user login" and click it.
    i = 0
    While i < objCollection.Length
        If objCollection(i).href Like "*llogin" Then
            objCollection(i).Click
            
            ' Wait while IE loading...
            Do While IE.Busy
                DoEvents
            Loop
            
            'clean
            Set objCollection = Nothing

            'skip to the part that logs you in
            GoTo Loggingin
        End If
        i = i + 1
    Wend
    
Loggingin:
    Set objCollection = IE.Document.getElementsByTagName("input")
 
    i = 0
    While i < objCollection.Length
        If objCollection(i).Name = "username" Then
 
            ' Set text for search
            objCollection(i).Value = myUsername
 
        ElseIf objCollection(i).Name = "password" Then
 
            ' Set text for search
            objCollection(i).Value = myPassword
 
        Else

            If objCollection(i).Name = "submitted" Then

                ' "login" button is found
                Set objElement = objCollection(i)
 
            End If
        End If
        i = i + 1
    Wend
    objElement.Click    ' click button to search
    
    ' Wait while IE re-loading...
    Do While IE.Busy
        DoEvents
    Loop
    
    
    
    ' Clean up
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing

Open in new window

0
 

Author Comment

by:HKH1967
ID: 37787339
INHOUSERES:
This time it open the login web but another error see attached.
err4.png
0
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 37787354
can you see if it adds the username and password to the boxes before the error?

Can you see the login button before the error?
0
 

Author Comment

by:HKH1967
ID: 37787372
sorry i have miss to inform you that it is not adding the user and password to the login screen
0
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 37787417
That code works fine for me :\
it obviously doesn't log in because it's not a real username/password, but I get:
Incorrect username or password!
[WC_0003]

what version of Internet explorer are you using?
I'm using IE9.
0
 

Author Comment

by:HKH1967
ID: 37787512
I am using IE9. i have attached the mdb file.
i have try to debug as per attached screen and after press f8 many times i have seen the user and password.
Database4.accdb
debug.png
0
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 37787537
your DB works fine with me too.

Do you perhaps have any scripts or add-ins with IE that may be slowing it down a bit? It seems that the code is running too fast before the page has fully loaded.
If it works when you use F8, it suggests that it needs more time before it runs that code.


Try adding before "Loggingin:" line:

for i = 1 to 1000
   DoEvents
Next i

Then see if it works.

(I'm actually away for the weekend, sorry - so I really hope that works!)
0
 

Author Comment

by:HKH1967
ID: 37787940
i try it but it give the same error
0
 

Author Closing Comment

by:HKH1967
ID: 37791799
thank alot  i have used the following function

Sub WaitFor(NumOfSeconds As Long)
Dim SngSec As Long
SngSec = Timer + NumOfSeconds
 
Do While Timer < SngSec
DoEvents
Loop
 
End Sub

and i have fix it i have mentioned before loggining line ''  Call WaitFor(12) ''

I will accept the solution but i will reopen the question again since i have another question related to same function u provide. thanks alooooot
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question