Announcement

Collapse
No announcement yet.

Run Time Error '91': Submitting a Form via VBA

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Run Time Error '91': Submitting a Form via VBA



    Hi guys

    after a little help from the collective please.

    I'm using PHP-Calendar on a website and have hit a small snag trying to add an event via automation.

    Everything's being run in a webbrowser object in a custom form and although I have successfully automated the login using .Document.all("Submit").Click inside a WITH I simply cannot get it to work from the Add Event Page

    The error I get when running is
    Run Time Error '91':
    Object variable or with Block variable not set

    All the form elements are filled in correctly and if i comment out the .Document.all("Submit").Click I can successfully create the Event clicking on the "Submit Event" button manually

    Using the "Inspect Element" feature in Chrome these are the two Input sections

    Working:
    <input name="submit" value="Log in" type="submit" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false">

    Non working:
    <input type="submit" value="Submit Event" class="ui-button ui-widget ui-state-default ui-corner-all ui-state-hover" role="button" aria-disabled="false">

    TIA

    Mike

    The offending Code Snippet is

    Code:
        With WebBrowser1
            .Navigate MyNewEvent
        
            'wait until page loads
                Do Until .ReadyState = 4
                    DoEvents
                Loop
            
            .Document.all("subject").Value = MySubject
            .Document.all("description").Value = MyDescription
            .Document.all("start-date").Value = MyStartDate
            .Document.all("end-date").Value = MyEndDate
            .Document.all("start-time").Value = MyStartTime
            .Document.all("end-time").Value = MyEndTime
            .Document.all("Submit").Click
        
            'wait until submission complete
            Do Until .ReadyState = 4
                DoEvents
            Loop
                
            .Navigate MyCalView
                   
        End With

  • #2
    Re: Run Time Error '91': Submitting a Form via VBA

    Apologies (and I know it's normally bad form to reply to your own post) but I've just managed to get it working

    Code:
        With WebBrowser1
            .Navigate MyNewEvent
        
            'wait until page loads
                Do Until .ReadyState = 4
                    DoEvents
                Loop
            
            .Document.all("subject").Value = MySubject
            .Document.all("description").Value = MyDescription
            .Document.all("start-date").Value = MyStartDate
            .Document.all("end-date").Value = MyEndDate
            .Document.all("start-time").Value = MyStartTime
            .Document.all("end-time").Value = MyEndTime
            '.Document.all("Submit").Click
            
                    Set objInputs = .Document.getElementsByTagName("input")
                        For Each obj In objInputs
                            If obj.Value = "Submit Event" Then Exit For
                        Next
                    obj.Click
        
            'wait until submission complete
            Do Until .ReadyState = 4
                DoEvents
            Loop
                
            .Navigate MyCalView
                   
        End With

    Comment


    • #3
      Re: Run Time Error '91': Submitting a Form via VBA

      I know it's normally bad form to reply to your own Post
      Why on Earth would you think that? Nice to see someone actually work it out instead of just waiting for an answer to be provided; even nicer, you had the courtesy to explain the solution.

      Well done. Post again soon (and that's not being sarcastic, unusually for me. )

      Comment


      • #4


        Re: Run Time Error '91': Submitting a Form via VBA

        Originally posted by cytop View Post
        Why on Earth would you think that? Nice to see someone actually work it out instead of just waiting for an answer to be provided; even nicer, you had the courtesy to explain the solution.

        Well done. Post again soon (and that's not being sarcastic, unusually for me. )
        It was one of those occasion where you read back what you have written and the answer is staring you in the face.

        The non working element doesn't have a "type=submit" in it so I went back to the full file source and found a second almost identical hidden element for the button but with the "type" declaration in so googled for an alternative solution to get it clicked

        Comment

        Working...
        X