Solved

MS access open web page

Posted on 2012-03-29
17
655 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
 

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now