Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Filling in Explorer Form Fields Programmatically? (Office 2000 SP 1A WinXP

    I have a webpage form with three fields and I would like to be able to extract data from an MS Access table or query to enter data in these fields to submit to the server.
    The page is of my own design so it won't suddenly change unexpectedly causing problems with the code - if such code can be written.
    Has anyone any idea of how you would go about this? (The Explorer object model is not well documented.)
    So, in summary: if I have three fields on an Access form with data then I want to be able to trigger some code via a command button (say) that will transfer the data in those three fields into the corresponding fields in the page at a given URL and then click the submit button on that page. Possible?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Filling in Explorer Form Fields Programmatical

    Microsoft supplies the InternetExplorer (named something like shdocvw.dll) and MSHTML object libraries which might do what you want: if your VBA procedure launches the Internet Explorer window, then your procedure is allowed to manipulate the contents of that window. However, if you wanted to start from an already open browser or page, I think the security model prevents you from changing it from the outside, at least using the ready-made methods.

    It has been quite a while since I coded anything like this, and my former working example has been rendered obsolete by changes in the form. Here are some code snippets that might help, but don't in and of themselves constitute a working solution:

    'Declare Sleep API
    Private Declare Sub Sleep Lib "kernel32" (ByVal nMilliseconds As Long)
    ---
    'Create browser object references
    Dim ieNew As New InternetExplorer

    'Load old page
    With ieNew
    .Visible = True 'show window
    .navigate "http://domain.com/folder/page.html" 'open page
    While Not .readyState = READYSTATE_COMPLETE
    Sleep 500 'wait 1/2 sec before trying again
    Wend
    End With

    'Create document object model references
    Dim ieDocNew As MSHTML.HTMLDocument
    Set ieDocNew = ieNew.Document

    'change input controls
    Dim newTag As HTMLHtmlElement
    ...

    'submit for validation
    Dim blnValidated As Boolean, btnSubmit As HTMLButtonElement
    blnValidated = False
    For Each newTag In ieDocNew.all.tags("INPUT")
    If UCase(newTag.Type) = "SUBMIT" Then
    Set btnSubmit = newTag
    btnSubmit.Click
    blnValidated = True
    Exit For
    End If
    Next

    In there I've skipped over some of the messy part of dealing with the Document Object Model. You may be able to adapt from JavaScript examples, but it is pretty frustrating, as I remember. Searching for some of these object model references in the same post might yield some helpful threads.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Filling in Explorer Form Fields Programmatical

    Thanks, just what I was looking for. I did a google and came up with some ready made code which I tested and it works perfectly:
    Here's where it is:
    http://www.motobit.com/tips/detpg_sendfrmie
    Rather handy!
    David

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •