• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 680
  • Last Modified:

MS access open web page

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
HKH1967
Asked:
HKH1967
  • 8
  • 7
  • 2
1 Solution
 
INHOUSERESCommented:
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
 
Jeffrey CoachmanMIS LiasonCommented:
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
 
Jeffrey CoachmanMIS LiasonCommented:
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
HKH1967Author Commented:
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
 
INHOUSERESCommented:
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
 
HKH1967Author Commented:
INHOUSERES:
the link is
http://www.world-check.com/
0
 
INHOUSERESCommented:
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
 
HKH1967Author Commented:
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
 
INHOUSERESCommented:
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
 
HKH1967Author Commented:
INHOUSERES:
This time it open the login web but another error see attached.
err4.png
0
 
INHOUSERESCommented:
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
 
HKH1967Author Commented:
sorry i have miss to inform you that it is not adding the user and password to the login screen
0
 
INHOUSERESCommented:
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
 
HKH1967Author Commented:
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
 
INHOUSERESCommented:
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
 
HKH1967Author Commented:
i try it but it give the same error
0
 
HKH1967Author Commented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 8
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now