Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MS access open web page

Posted on 2012-03-29
17
Medium Priority
?
674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 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