How to modify my current vba code to select the value in an IE dropdown menu verses making the value equal to it?

When I use the below code it changes the value in the IE form, but when I click submit the value reverts back to the original setting.   The spelling is correct.  With an invalid value the value disappears.  I hoping that by selecting the option instead of just changing the value the new value will be accepted.

                Set objFound = objFrameDoc.getElementById("X46")
                If objFound Is Nothing Then
                    
                Else
                    objFound.Value = "Rejected"
                End If

Open in new window

kbay808Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Zack BarresseCEOCommented:
I would assume it's in your click code. If you've got the element by Id and are able to set it's value then that's fine. There's no other code posted so it's kind of hard to do anything except speculate. I would want to know how you're clicking the submit button. It should be something like "submitButton.click".

Of course you're at the mercy of the website too. For example if they have some JavaScript running when the button is clicked, and if that is changing the value of your "X46" Id object, then there's not much you can do.

If you want to use Early Binding for this, you'd need to set a reference to 'Microsoft HTML Object Library', and your objects would be declared as 'MSHTML.HTMLInputElement' type.

Regards,
Zack Barresse
0
kbay808Author Commented:
I did not automate the submit button.  That way the user has a chance to add any additional notes.  I attached a screen shot of the website and posted the complete code that I’m using below.  

Sub RejectTicketMissingType2()

    Dim objIE As SHDocVw.InternetExplorer
    Dim objShell As SHDocVw.ShellWindows
    Dim objIEDoc As MSHTML.HTMLDocument
    Dim objFound As MSHTML.HTMLBaseElement
    Dim strURL As Variant
    Dim blnFoundWebSite As Boolean
    Dim objDialog As FileDialog
    Dim objFSO As Scripting.FileSystemObject
    Dim objText As Scripting.TextStream
    Dim objDebugFile As Scripting.TextStream
    
    Dim varFrame As Variant
    Dim varFrame2 As Variant
    Dim objFrameDoc As MSHTML.HTMLDocument
    Dim objFrameDoc2 As MSHTML.HTMLDocument
    Dim i As Integer
    Dim j As Integer
    
    Dim objElem As MSHTML.HTMLBaseElement
    Dim objElemDoc As MSHTML.HTMLDocument
    Dim objElem2 As MSHTML.HTMLBaseElement
    Dim objElemDoc2 As MSHTML.HTMLDocument

        
    Set objShell = New SHDocVw.ShellWindows
    Set objFSO = New Scripting.FileSystemObject
    ' **** Set the Web Address Here ****
    strURLS = "https://servman/sm/index.do,https://servman/sm/index.do?lang=en&mode=index.do,https://servman/sm/index.do?lang=en&mode=index.do&logout_msg=LogoutPage.session_timeout"
  
    ' Look for the appropriate open IE Window
    For Each objIE In objShell
        If TypeOf objIE.document Is MSHTML.HTMLDocument Then
            Set objIEDoc = objIE.document
            If Not (objIEDoc Is Nothing) Then
                For Each strURL In Split(strURLS, ",")
                    If objIEDoc.url = strURL Then
                        blnFoundWebSite = True
                        Exit For
                    End If
                Next
                If blnFoundWebSite = True Then Exit For
            End If
        End If
    Next
    
    Set objFrameDoc2 = objIEDoc

    If blnFoundWebSite Then
        ' Make sure IE is done loading the page
        Do Until Not objIE.Busy
            DoEvents
        Loop
        
        ' Make Sure we had some frames returned
        If objIEDoc.frames.Length > 0 Then
            ' Get the Document from the 1st Frame
            Set varFrame = objIEDoc.frames.Item(0)
            Set objFrameDoc = varFrame.document
            
            ' Get the Detail Frame (Sub Frame #2)
            If objFrameDoc.frames.Length > 1 Then
                Set varFrame2 = objFrameDoc.frames.Item(1)
                Set objFrameDoc2 = varFrame2.document
                
                'Status
                
                'Set objFound = objFrameDoc2.getElementById("X46")
                'If objFound Is Nothing Then
                    
                'Else
                    'objFound.Value = "Rejected"
                'End If
                
                'Update
                
                Set objFound = objFrameDoc2.getElementById("X159")
                If objFound Is Nothing Then
                    
                Else
                    objFound.Value = "Missing Type 2 ticket"
                End If
                
                'Reason
                
                Set objFound = objFrameDoc2.getElementById("X230")
                If objFound Is Nothing Then
                    
                Else
                    objFound.Value = "incomplete information"
                End If
                
                'Rejection Details
                
                Set objFound = objFrameDoc2.getElementById("X232")
                If objFound Is Nothing Then
                    
                Else
                    objFound.Value = "Missing Type 2 ticket"
                End If
              
                                
            Else
                        
                'Status
                
                'Set objFound = objFrameDoc.getElementById("X46")
                'If objFound Is Nothing Then
                    
                'Else
                    'objFound.Value = "Rejected"
                'End If
                
                'Update
                Set objFound = objFrameDoc.getElementById("X159")
                If objFound Is Nothing Then
                    
                Else
                    objFound.Value = "Missing Type 2 ticket"
                End If
                
                'Reason
                
                Set objFound = objFrameDoc.getElementById("X230")
                If objFound Is Nothing Then
                    
                Else
                    objFound.Value = "incomplete information"
                End If
                
                'Rejection Details
                
                Set objFound = objFrameDoc.getElementById("X232")
                If objFound Is Nothing Then
                    
                Else
                    objFound.Value = "Missing Type 2 ticket"
                End If
                
            End If ' objFrameDoc.frames.Length > 1
        End If ' objIEDoc.frames.Length > 0
        
        
        
    End If
    
    
    Set objIE = Nothing
    Set objShell = Nothing
    Set objIEDoc = Nothing
    Set objIEDoc = Nothing
    Set objFound = Nothing
    Set objDialog = Nothing
    Set objFSO = Nothing
    Set objText = Nothing
    Set objDebugFile = Nothing
End Sub

Open in new window

Screen-Shot.jpg
0
Zack BarresseCEOCommented:
Those are restricted IP's I cannot access. I'm also not sure where you're setting the variable for the submit button. With your browser open you should be able to right click the button and select "Inspect Element" and you'll see the HTML for that element highlighted. You'll need to get the element Id or Class name, whichever will uniquely identify that object.

What I generally do is set my variable, let's assume for a moment you declared this variable...
        Dim objSubmit As MSHTML.HTMLInputElement

Open in new window


You could then set it something like this...
        Set objSubmit = objFrameDoc.getElementById("submit button Id goes here")

Open in new window


Or if you only know the class name you can set it something like this...
        Set objSubmit = objFrameDoc.getElementsByClassName("class name of element goes here").Item

Open in new window


Then you could click it something like this...
        objSubmit.Click

Open in new window


HTH
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

kbay808Author Commented:
I’m not trying to select the submit button.  Per the screen shot I previously attached, there is a dropdown box with 6 options.  If I select “Rejected” from the dropdown menu and then click submit it works fine.  When I use the below vba code to change the value the value will change, but when I click submit, the change won’t save.  What I’m trying to do is to simulate selecting the dropdown menu and selecting “Rejected”.

           Set objFound = objFrameDoc.getElementById("X46")
                If objFound Is Nothing Then
                    
                Else
                    objFound.Value = "Rejected"
                End If

Open in new window

0
Zack BarresseCEOCommented:
It's possible the drop-down has a JS function attached to it. I'd change the drop-down to "Rejected" and re-inspect the element. Maybe there's something else happening besides the value changing. Without being able to view the website and re-create your situation, it's hard to give you anything else.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kbay808Author Commented:
Thanks for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.