Solved

MS access open web page

Posted on 2012-03-29
17
652 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:HKH1967
Comment Utility
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
Comment Utility
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
Comment Utility
INHOUSERES:
the link is
http://www.world-check.com/
0
 
LVL 5

Expert Comment

by:INHOUSERES
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 5

Accepted Solution

by:
INHOUSERES earned 500 total points
Comment Utility
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
Comment Utility
INHOUSERES:
This time it open the login web but another error see attached.
err4.png
0
 
LVL 5

Expert Comment

by:INHOUSERES
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
i try it but it give the same error
0
 

Author Closing Comment

by:HKH1967
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Internet is a big network which is formed by connecting multiple small networks.It is a platform for all the users which are connected to it.Internet act as platform in different fields. Such as: Internet  as a collaboration platform. Internet  as…
I recently found myself in a Corporate Situation where the client had requested blocking access to any and all websites except his own Domain? Easy? I am sure this would be your answer but their requirement was, this has to be done without using…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

762 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

10 Experts available now in Live!

Get 1:1 Help Now