Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Check if Page is Opened

Discussion in 'Information Technology' started by Ryan, Jul 28, 2006.

Tags:
  1. Ryan

    Ryan
    Expand Collapse
    Guest

    Hi. I am just starting out with VBA in Access. I am trying to have Access
    open a web page. I can do that, but I also want to make sure the web page
    has loaded within, say, 20 seconds.

    I've been thinking of something like:

    using AppActivate with the title of the page that it displays when it has
    loaded and then repeating this action if there is an error (ie, no such
    title, bc the page hasn't loaded) and if a counter has not been exceeded.

    I'm not really sure how to put that together though. Any ideas??

    Thanks,
    Ryan
     
  2. Loading...


  3. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    What exactly do you mean by having "Access open a web page"? Are you
    strictly trying to open an instance of Internet Explorer and have the page
    appear there, or do you have an instance of the Microsoft Web Browser
    ActiveX control on a form in Access? If the latter, there's a
    DownloadComplete event that you should be able to tap into.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no private e-mails, please)


    "Ryan" <Ryan@discussions.microsoft.com> wrote in message
    news:17E8CDFA-69CF-4B39-A349-7C630E3C10BD@microsoft.com...
    > Hi. I am just starting out with VBA in Access. I am trying to have
    > Access
    > open a web page. I can do that, but I also want to make sure the web page
    > has loaded within, say, 20 seconds.
    >
    > I've been thinking of something like:
    >
    > using AppActivate with the title of the page that it displays when it has
    > loaded and then repeating this action if there is an error (ie, no such
    > title, bc the page hasn't loaded) and if a counter has not been exceeded.
    >
    > I'm not really sure how to put that together though. Any ideas??
    >
    > Thanks,
    > Ryan
     
  4. Ryan

    Ryan
    Expand Collapse
    Guest

    Hi Doug,

    Thanks for the input. I am not doing anything too involved and I am not
    using ActiveX (that's way over my head).

    What I am trying to do is eliminate duplicate entry of data.

    The data that gets entered into Access (via a form) also needs to be entered
    into a third party web form. After the user has input a new record, I would
    like them to be able to 'click a button' and have all that data entered into
    the web form automatically. I have it working right now, but I am sure the
    coding is not optimal.

    The steps are:
    1) Open web page.
    2) Login.
    3) Navigate to appropriate page.
    4) Transfer data from access form fields to web form fields.

    The thing that makes it easy (or doable at all with my limited skills) is
    the fact that the web site can be navigated solely through keyboard commands.
    So I am pretty much accomplishing everything through SendKeys.

    I do not have a great way of knowing if and when the webpage has loaded,
    though. My code works, but I am wondering if anyone could throw a few
    pointers or tips my way. Here is the code (please do not laugh):


    Private Sub EnterWebData_Click() 'Code behind button

    Dim Login_Count
    Login_Count = 0

    Call OpenGump

    Do 'Loop to check if page has loaded
    Call PageCheck

    If PageCheck = False Then
    Call Wait(2)
    Else: Exit Do
    End If

    Login_Count = Login_Count + 1
    Loop Until Login_Count = 10

    If PageCheck = False Then
    MsgBox "Could not connect"
    Exit Sub
    End If

    Call LoginGump

    End Sub


    Function OpenGump() 'open web page
    On Error GoTo OpenGump_Err

    FollowHyperlink "-web address here-"

    OpenGump_Exit:
    Exit Function

    OpenGump_Err:
    MsgBox Error$
    Resume OpenGump_Exit

    End Function


    Function PageCheck() As Boolean 'test to see if page has loaded
    On Error GoTo ErrHandle
    PageCheck = True
    AppActivate "user details" 'try to move focus to login page
    Exit Function

    ErrHandle: 'if could not move focus, page not loaded (yet)
    PageCheck = False
    Exit Function

    End Function


    Function Wait(z As Integer) 'pause
    Dim x, y As Integer
    x = 1
    y = 1
    Do
    Do
    x = x + 1
    Loop Until x = 9000

    x = 1
    y = y + 1

    Loop Until y = (z * 1000)
    End Function

    Function LoginGump() 'log in to site (send userid and pswd)

    SendKeys "-userid-", 1
    Call Wait(1)
    SendKeys "{TAB}", 1
    Call Wait(1)
    SendKeys "-password-", 1
    SendKeys "{Enter}", 1



    Thanks,
    Ryan
     
  5. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    SendKeys is notoriously problematic: it's too easy to change what's got
    focus so that it doesn't do what you intend it to. I'd suggest not using it.

    However, if the 3rd party doesn't offer a more reliable approach, I'm afraid
    I can't offer you any alternative.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Ryan" <Ryan@discussions.microsoft.com> wrote in message
    news:AE3DD540-424D-49FA-A186-5AA9E6728A25@microsoft.com...
    > Hi Doug,
    >
    > Thanks for the input. I am not doing anything too involved and I am not
    > using ActiveX (that's way over my head).
    >
    > What I am trying to do is eliminate duplicate entry of data.
    >
    > The data that gets entered into Access (via a form) also needs to be

    entered
    > into a third party web form. After the user has input a new record, I

    would
    > like them to be able to 'click a button' and have all that data entered

    into
    > the web form automatically. I have it working right now, but I am sure

    the
    > coding is not optimal.
    >
    > The steps are:
    > 1) Open web page.
    > 2) Login.
    > 3) Navigate to appropriate page.
    > 4) Transfer data from access form fields to web form fields.
    >
    > The thing that makes it easy (or doable at all with my limited skills) is
    > the fact that the web site can be navigated solely through keyboard

    commands.
    > So I am pretty much accomplishing everything through SendKeys.
    >
    > I do not have a great way of knowing if and when the webpage has loaded,
    > though. My code works, but I am wondering if anyone could throw a few
    > pointers or tips my way. Here is the code (please do not laugh):
    >
    >
    > Private Sub EnterWebData_Click() 'Code behind button
    >
    > Dim Login_Count
    > Login_Count = 0
    >
    > Call OpenGump
    >
    > Do 'Loop to check if page has loaded
    > Call PageCheck
    >
    > If PageCheck = False Then
    > Call Wait(2)
    > Else: Exit Do
    > End If
    >
    > Login_Count = Login_Count + 1
    > Loop Until Login_Count = 10
    >
    > If PageCheck = False Then
    > MsgBox "Could not connect"
    > Exit Sub
    > End If
    >
    > Call LoginGump
    >
    > End Sub
    >
    >
    > Function OpenGump() 'open web page
    > On Error GoTo OpenGump_Err
    >
    > FollowHyperlink "-web address here-"
    >
    > OpenGump_Exit:
    > Exit Function
    >
    > OpenGump_Err:
    > MsgBox Error$
    > Resume OpenGump_Exit
    >
    > End Function
    >
    >
    > Function PageCheck() As Boolean 'test to see if page has loaded
    > On Error GoTo ErrHandle
    > PageCheck = True
    > AppActivate "user details" 'try to move focus to login page
    > Exit Function
    >
    > ErrHandle: 'if could not move focus, page not loaded (yet)
    > PageCheck = False
    > Exit Function
    >
    > End Function
    >
    >
    > Function Wait(z As Integer) 'pause
    > Dim x, y As Integer
    > x = 1
    > y = 1
    > Do
    > Do
    > x = x + 1
    > Loop Until x = 9000
    >
    > x = 1
    > y = y + 1
    >
    > Loop Until y = (z * 1000)
    > End Function
    >
    > Function LoginGump() 'log in to site (send userid and pswd)
    >
    > SendKeys "-userid-", 1
    > Call Wait(1)
    > SendKeys "{TAB}", 1
    > Call Wait(1)
    > SendKeys "-password-", 1
    > SendKeys "{Enter}", 1
    >
    >
    >
    > Thanks,
    > Ryan
    >
     

Share This Page