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...
Below is where I'm getting the runtime error 91. When I step through manually everything works fine with no error...
The other problem I found a workaround for which I'm sure is not ideal is this...
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!
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!