Results 1 to 10 of 10
  1. #1
    Angrybox is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    3

    Error Attempting to Export Data to IE9

    Hey All,
    I'm trying to make a button in my form that will export some of my fields into text fields on a website. I've been using this tutorial: http://www.access-programmers.co.uk/...d.php?t=176968

    Here's my code:
    Code:
    Private Sub autoexport_Click()
    Dim ie As Object
    Set ie = CreateObject("internetexplorer.application")
    
    
    ie.Visible = True
    ie.navigate "http://mywebsite.etc"
    While ie.busy
                DoEvents
             Wend
    ie.Document.getElementById("tbxTextField1").Value = "Test 123"
    End Sub
    Problem is every time it tries to run I get the following error:


    Code:
    Run-time error '-2147467259 (80004005)':
    Method 'Document' of object 'IWebBrowser 2' failed
    Based on some googling it seems it may have something to do with IE9. Do any of you have experience with this kind of work and might be able to assist?

  2. #2
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    2 things you should know about this here:

    1st => when you use the code to wait for ie.busy to return FALSE, it's not reliable because there are other factors involved with the return val of that function. I don't know what they are, but there is no identifiable point where an ie browser can tell visual basic that the page is "loaded". so don't rely on that. I believe the equivalent enumeration value for the check is 4. in other words, ie.readystate = 4 means "page is loaded completely." but that's not reliable either. no idea if it's reliability percentage is better though.

    2nd => check your references first. "
    IWebBrowser" is a DLL object that's been a representation of internet explorer for quite some time now, but in either office 2010 or windows 7, the association of it with office and visual basic very well may have changed. I'm doubting it has anything to do with timing of the web page load, because, if you tried to throw a val into a web element like in the case here, the error would be:


    "error, data member or method not found". (or something similar).


    by the way, -21474677259 is the default value for 32-bit memory allocation for error numbers (I think). What this basically means, I believe, is that the program is telling you it has no idea what's wrong.

    my guess would be that, since your office bits and windows bits are congruent, it's an issue with IE9 that's built into win 7. can you downgrade it? can you ditch it and revert to IE8? that would be the first I would do.

    by the way, look at this too:
    http://support.microsoft.com/kb/286126

    that applies to .NET and using the webforms-type application in .NET, but the same concept still applies. VB.NET is, for all practical purposes, is just visual basic legacy that was given a makeover by rolling it into the differentiated server-based code syntaxes so MS could produce multiple revenue streams for the company.

  3. #3
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I hope I don't confuse ya further... but I interact with 9.0, I will post the code I use.. it will 3 different sets of code. The first is the code that opens IE, navigates to the website, grabs creds from a table and passes them to IE.

    Code:
    Sub AuthData()
    
    
    Dim aDa As InternetExplorer
    Dim User, Pass As String
    
    
      On Error Resume Next
     ' This is where creds are stored.
      User = DLookup("[chrWebuser]", "tblWebCreds", "chrWebTools='Network Credentials'") 
      Pass = DLookup("[chrWebpass]", "tblWebCreds", "chrWebTools='Network Credentials'")
      If Err.Number = 94 Then
        MsgBox "Username or Password is missing", , "LIFT MESSAGE"
        DoCmd.OpenForm "frmWebCreds"
        Exit Sub
        End If
    
    
      Set aDa = Login("Website we are going to", True)
    ' I will attach another code window for SleepIE
      Call SleepIE(aDa)
    'P101_USERNAME is the spot we want to pass user into.
    ' P101_PASSWORD is the spot we want to pass pass into
      aDa.Document.all.Item("P101_USERNAME").Value = User
      aDa.Document.all.Item("P101_PASSWORD").Value = Pass
      Call SleepIE(aDa)
    
    
      aDa.Navigate "javascript:doSubmit('LOGIN');"
      
      Call SleepIE(aDa)
      
        ''''''''''''credentials check   if the page says Invalid login credentials on the body, it prompts a 
    'msg box thru java on the page. 
          If InStr(aDa.Document.Body.innertext, "Invalid Login Credentials") > 0 Then
            aDa.Navigate "javascript:alert('Please Check your credentials.');"
          Exit Sub
      End If
      
     ' the button we want to click on the page.
      aDa.Navigate "javascript:doSubmit('SUBMIT');"
    
    
    End Sub
    Okay, so thats the functioning bit of code. Below is going to be the SleepIE bit, and below that is going to be the internetexplorer bit.

    Code:
    Sub SleepIE(oIE As InternetExplorer)
    
    
      Do While oIE.Busy: DoEvents: Loop
      Do While oIE.ReadyState <> 4: DoEvents: Loop
      Do While oIE.Document.ReadyState <> "complete": DoEvents: Loop
      
    End Sub
    Below is the IE part, it has a built in check for security certificate, this can be ignored if not needed but it should not harm anything.

    Code:
    Function Login(Address As String, AutoLog As Boolean) As InternetExplorer
    
    
      Dim oIE As InternetExplorer
      Set oIE = New InternetExplorer
              
      oIE.Visible = True
      
      oIE.Navigate Address
      Call SleepIE(oIE)
      If InStr(oIE.Document.Body.innertext, "There is a problem with this website's security certificate.") > 0 Then
        oIE.Navigate "javascript:alert('Please resolve security certificate issue.');"
        DoEvents
        Do Until InStr(oIE.Document.Body.innertext, "Username") > 0
        PauseApp 1
        Loop
        End If
      If AutoLog = False Then MsgBox "Please login.", , "LIFT MESSAGE"
      Set Login = oIE
     End Function
    I know its a lot of code, but it runs pretty solid. the entire process above takes 1.2 seconds important to note, this code depends on a table to have stored credentials in it. This is easily replaced with a text box on your form, or simply hard coded. Just depends on your needs. I apologize if this is not what you are looking for.. but in the rare case I can help, I like to try.

    - Additional note... if your webpage is using Java, these SleepIE things don't work very well. I actually had to use hard pauses... Code below.

    Code:
    Public Sub PauseApp(PauseInSeconds As Long)
        
    Call AppSleep(PauseInSeconds * 1000)
    ' So when giving a javasite time to load, I just use a  hardpause 
      appsleep .5 or something along those lines.     
    End Sub
    I really hope this helps, I am having an issue with nulls that kind of has me at a stand still... any clarification is needed reply and I'm on it.

    ---- ANOTHER ADDITIONAL NOTE... the example above uses javascript, so the button click for submit looks like this ..
    aDa.Navigate "javascript:doSubmit('SUBMIT');"
    IF you are on a basic html site.... use this..
    aDa.Document.all.Item("SUBMIT").Click
    ...

  4. #4
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    RedBull,

    What library is this coming from?

    Code:
    Dim aDa As InternetExplorer

  5. #5
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Hmm, I am assuming its... "Microsoft internet controls"

    But in case it is not.. here is a list of what I am currently using in that app.

    Visual Basic for Applications
    Microsoft Access 11.0 Object Library
    OLE Automation
    Microsoft DAO 3.6 Object Library
    Microsoft ActiveX Data Objects 2.1 Library
    Microsoft Internet Controls
    Microsoft Outlook 11.0 Object Library.

  6. #6
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    it's this: Microsoft Internet Controls


    that actually makes me feel pretty stupid. I wonder how long that library has been deployed with office programs? in all my time automating IE navigation, I have always created the object instance. but I may just play with this. at this point I'm assuming it's a very small lib.

  7. #7
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I hope the OP finds it useful, or anyone for that matter. I am pretty new to VBA, just started doing it back in feb but I've gotten a TON of great advice from this forum.

  8. #8
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    if you want to get ahead of the game, try getting used to MS's .NET technologies. It's all one concept, but the resources list of the entire software stack is freakin endless. Apparently the pay for jobs that deal with those technologies are also high.

    My belief is, aside from small business people and individual hobbyists, eventually all business-related and BI-related scripting will be based off the squigglies and nothing else. you know, the "{}" stuff. like Java! C# is pretty interesting to work with, more or less because of it's architecture and the purposes you can discover behind all of the different resources for it to operate on a server. things like class hierarchies, universal directives, configurations, XML stuff, yada yada...the possibilities are endless. a life long learning experience for sure. I'm not convinced there's any point to it, but it can be fun if you have nothing to do and need to kill an afternoon!


    embrace the squigglers! they're coming for us!

  9. #9
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Yea, that is the ultimate goal... Just seems like such a monster, it is intimidating... BUT as I become more confident in this (VBA) I imagine that fear will subside.

    Apparently the pay for jobs that deal with those technologies are also high.
    To be honest, thats the goal lol.

  10. #10
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    well I know it is for ME! dude...to be honest with you, if you can set up your own testing environment with .NET, you'll soon realize that most of the resources in it is virtually all the same thing. didn't I just say that earlier....??

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Export to Excel Error Handling
    By TimMoffy in forum Programming
    Replies: 1
    Last Post: 06-06-2012, 05:40 AM
  2. Error when trying to export from table to Excel
    By tobinjames in forum Import/Export Data
    Replies: 3
    Last Post: 12-15-2011, 02:55 PM
  3. Macro export to excel error
    By Andy_d in forum Import/Export Data
    Replies: 7
    Last Post: 04-15-2011, 09:54 AM
  4. Replies: 0
    Last Post: 02-26-2011, 06:54 AM
  5. Replies: 0
    Last Post: 08-10-2010, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums