Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Throwing Runtime Error 91 when completing webform...?

Status
Not open for further replies.

MrTrue

Technical User
Jul 28, 2008
46
US
I have two small issues I'm trying to sort out, I have a website I need to access that I log into and submit data. I'm not an experienced programmer, and I can't quite figure out what the issue is. I've been researching the runtime error 91 and I've figured out that it's probably due to an incorrectly defined object. The problem is this... When I step through the code, it works perfectly... When I compile the entire sub I get the error. I'll post the whole block of code below, then I'll break out my two trouble spots...

Code:
Private Sub CommandButton2_Click()
   Dim objIE As Object
      Set objIE = CreateObject("InternetExplorer.Application")
          With objIE
              .Navigate "[URL unfurl="true"]https://www.MyWebSite.com/myframe.asp?usermode=1"[/URL]
              Do While .Busy: DoEvents: Loop
              Do While .readyState <> 4: DoEvents: Loop
             .Visible = True
            
             With objIE.document.frames("MainContent").document.forms(Form1)
On Error GoTo NextLine
                 .GroupUserName.Value = "User"
                 .GroupPassword.Value = "Pass"
                 .UserName.Value = "User"
                 .Password.Value = "Pass"
                 .ActionButt.Click
             End With
             
NextLine:
              
              Do While .Busy: DoEvents: Loop
              Do While .readyState <> 4: DoEvents: Loop
             
             With objIE.document.frames
                 .MainContent.Location = "/NewClients/clients/data_entry.asp"
             End With
             
             Do While .Busy: DoEvents: Loop
             Do While .readyState <> 4: DoEvents: Loop
                         
             With objIE.document.frames("MainContent").document.forms(0)
                 .ssnum.Value = "xxxxxxxxx"
                 .lname.Value = "Test"
                 .fname.Value = "Test"
                 .submitform.Click
                
             End With
             
              Do While .Busy: DoEvents: Loop
              Do While .readyState <> 4: DoEvents: Loop
             
             With objIE.document.frames("MainContent").document.forms("ClaimInfo")  ‘Throws run-time ‘91
            
                 .db_ProviderTitle.Value = "DR."
                 .db_ProviderLastName.Value = "John"
                 .db_ProviderFirstName.Value = "Doe"
                 .db_ProviderPhoneNumber.Value = "515-555-5555"
                 .db_ProviderAddress.Value = "110 S. Main St."
                 .db_ProviderCity.Value = "Hometown"
                 .db_ProviderState.Value = "IA"
                 .db_ProviderZipCode.Value = "55555"
                
             End With
             
         End With
            
         Set objIE = Nothing
End Sub

Below is where I'm getting the runtime error 91. When I step through manually everything works fine with no error...

Code:
With objIE.document.frames("MainContent").document.forms("ClaimInfo")  ‘Throws run-time ‘91

The other problem I found a workaround for which I'm sure is not ideal is this...

Code:
             With objIE.document.frames("MainContent").document.forms(Form1)
On Error GoTo NextLine
                 .GroupUserName.Value = "User"
                 .GroupPassword.Value = "Pass"
                 .UserName.Value = "User"
                 .Password.Value = "Pass"
                 .ActionButt.Click
             End With
             
NextLine:

The site will bypass this login screen if I've logged in recently, so to stop an error from throwing, I added the nextline errorhandler to bypass the password values, I'm sure this isn't the best way to handle this, but I'm not finding as much information about automating webforms as I thought I would. Any advice would be greatly appreciated! Thanks everyone!
 
In case anyone is interested, I did find my problem for the runtime error... For some reason the " with statement " was not recognizing the object prior to moving on to fill in the textboxes... I remedied this by setting the focus on the first textbox prior to continuing the code as follows...

Code:
 With objIE.document.frames("MainContent").document.forms("ClaimInfo")  
                 .db_ProviderTitle.Focus   '(Added this one Line)         
                 .db_ProviderTitle.Value = "DR."

If anyone knows what I can add to the code so that if I'm already logged into the site it uses the open instance of Explorer, I'm still working on that one. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top