Code using IE fails for one user only

Peter h

Active Member
Joined
Dec 8, 2015
Messages
417
So, I've got this code I've been using for well over a year now. Other than minor tweaks, I haven't had any issues since I've finished the project. Well, now for some reason, something has changed and I cannot figure out for the life of me what it is, or what's causing this very strange issue. Here's the issue, in a nutshell, that's happening. I have 10 users that share 2 computers at work, so the file is stored on a network drive. I don't have the file setup to be shared, so only 1 person can make changes at a time. The file and all of it's functions work absolutely fine with every user, except for 1 specific employee. I cannot figure out what would be causing the issues with 1 user and not all users. I know for a fact that he is accessing the correct file on the network (not just a shortcut on his desktop), because as I was trying to fix the issue, the file he was using had my "Fixes", but it never fixed the issue. I'll post some of the code, so maybe someone can spot something that might be causing this. And if anyone has any ideas I can try, or any ideas about what might be causing this, I really would appreciate some help. Thanks.

There are only 2 places in my project that use Environ("Username") to dictate what the code does. In my Workbook_Open sub I'm only using it to store a list of users that use the form, and to show an "Updates" userform. This userform is only ever used if there are changes made to the form that need to be communicated to the employee.
Code:
Private Sub Workbook_Open()
Module1.Add_Schedule_Event_in_VBA
Dim lastrow As Long, r As Long
lastrow = Sheets("Sheet2").Range("K" & Rows.Count).End(xlUp).Row

If Environ("Username") = "phobbs" Then
    ActiveWorkbook.Unprotect "SiqCreations1"
    Sheet9.Visible = xlSheetVisible
End If
Call TimeSetting
With Sheets("Sheet2")
    For r = 1 To lastrow + 1
        If .Cells(r, 11).Value = Environ("Username") Then
            Exit For
        ElseIf .Cells(r, 11).Value = "" Then
        ThisWorkbook.Sheets("Sheet2").Cells(lastrow + 1, 11) = Environ("Username")
        ThisWorkbook.Sheets("Sheet2").Cells(lastrow + 1, 12) = Format(Now, "mm/dd/yy hh:mm")
        End If
    Next r
End With
lastrow = lastrow + 1
For Each Cell In Sheets("Sheet2").Range("K1:K" & lastrow)
    If Cell.Value = Environ("UserName") Then
        If ThisWorkbook.Sheets("Sheet2").Cells(Cell.Row, 13) = "" Then
            UpdatesForm.Show
            ThisWorkbook.Sheets("Sheet2").Cells(Cell.Row, 13) = "1"
            Exit For
        End If
    End If
Next Cell
data_entry_2.Show vbModeless
End Sub

The only other place I use Environ("Username") is to set a combobox selection when I make a selection from a listbox.
Code:
Private Sub lb_type_Click()
Dim x As String
Dim anarng As Range
Set anarng = ThisWorkbook.Sheets("Sheet2").Range("K2:K10")
For Each Cell In anarng
    If Environ("UserName") = Sheets("Sheet2").Cells(Cell.Row, "K").Value Then
        x = Sheets("Sheet2").Cells(Cell.Row, "O").Value
    End If
Next Cell
   Call TimeStop
   Call TimeSetting
    tb_arrivaltime = Now
    tb_arrivaltime = Format(tb_arrivaltime.Value, "mm/dd/yyyy hh:mm")
    tb_sampletime = Now
    tb_sampletime = Format(tb_sampletime.Value, "mm/dd/yyyy hh:mm")
'Reset Form
Call Reset_Form
cb_analyst = x

My first thought was that because I use Environ to manipulate parts of my project, that that was the reason it was only messing up with 1 certain user. But the issues that are happening aren't coming from these to parts of code, so I'm inclined to rule these out.

My userform stores data to the worksheet, and also a webform in the companies network. The user submitting the data to the webform is where the issue lies. Here's the code that does that.
Code:
Private Sub btn_pi_Click()
Dim i As Integer
i = Me.lb_type.ListIndex
If i <= 6 Then
            With Me.lb_type
                If .Selected(0) = True Then efs_Web
                If .Selected(1) = True Then efmWeb
                If .Selected(2) = True Then isaWeb
                If .Selected(3) = True Then convWeb
                If .Selected(4) = True Then revWeb
                If .Selected(5) = True Then feedWeb
                If .Selected(6) = True Then otherWeb
            End With
End If
CheckEntered
'
'   ***   Reset Form   ***
'
Call Reset_Form
lb_type.Value = ""

End Sub

'This is only for 1 of the Listbox selections from ^Above. Each selection has different data that get's entered, but the url for each one is the same.

Private Sub efs_Web()
Dim IE As InternetExplorerMedium
Dim targetURL As String
Set IE = Nothing
targetURL = "[I][URL="http://miap33wsapx16/asoma/asomaentryform.aspx"]My URL Goes Here[/URL][/I]"
Set IE = New InternetExplorerMedium
    IE.Visible = False
    IE.Navigate targetURL
    Do Until IE.ReadyState = READYSTATE_COMPLETE
        DoEvents
    Loop
         IE.Document.getElementById("ddlSelection").selectedIndex = lb_type.ListIndex + 1
         IE.Document.getElementById("ddlSelection").FireEvent ("onchange")
        
        Do
            DoEvents
        Loop While IE.Document.getElementById("Sample_Arrival_Time") Is Nothing And IE.Document.getElementById("btnOK") Is Nothing
    
    If Not IE.Document.getElementById("btnOK") Is Nothing Then
        MsgBox "There seems to be an issue connecting to the Pi Server." & vbNewLine & _
        "Please check the old entry form to make sure there are no network issues."
        Exit Sub
    End If
Set efs = IE.Document
    With efs
        [COLOR=#ff0000].getElementById("Sample_Arrival_Time").Value = tb_arrivaltime.Value
        .getElementById("SampleTaken").Value = tb_sampletime.Value
        .getElementById("Control_Room_Operator").selectedIndex = cb_cro.ListIndex + 1
        .getElementById("Analyst").selectedIndex = cb_analyst.ListIndex + 1[/COLOR]
        .all("Copper").Value = tb_cu.Value   'Cu
        .all("Iron").Value = tb_fe.Value   'Fe
        .all("Sulfur").Value = tb_s.Value   'S
        .all("Silica").Value = tb_si.Value   'Si
        .all("Lime").Value = tb_ca.Value   'Ca
        .all("Alumina").Value = tb_al.Value   'Al
        .all("Magnetite").Value = tb_mag.Value   'mag
    End With
        If chb_ave = False Then
            efs.getElementById("Incl_Daily_Average").Click
        End If
        efs.getElementById("btnAccept").Click    
    
Set efs = Nothing
IE.Quit
Set IE = Nothing
End Sub
The Red highlighted part of the code is where we're having the issues. It's not throwing any errors, but the code is just not populating the webform for those elements. I thought maybe it was because I used getElementById, instead of "All" (like for the other elements), but like I said, the userform works for everyone but the 1 employee.

I know it's not that the employee is having issues accessing the webform, because ever since this issue sprung up, he has been having to enter the data onto the webform manually.

Does anyone have any ideas, or suggestions? Thanks.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Your code doesn't compile for me - it highlights 'InternetExplorerMedium' and says User-defined type not defined.

You haven't said what happens with this particular user - does the code fall over, or just fail to run? Is it possible they have a different version of IE, or different security settings?
 
Upvote 0
Your code doesn't compile for me - it highlights 'InternetExplorerMedium' and says User-defined type not defined.

You haven't said what happens with this particular user - does the code fall over, or just fail to run? Is it possible they have a different version of IE, or different security settings?

I'm not exactly sure what's happening. The code doesn't break or throw errors. It goes through the code just fine, but in my last block of code in my original post, the highlighted lines just don't populate those specific elements in the webform. I've changed IE to visible to watch as he uses the form, and all the other elements after those highlighted get populated fine, so I know the code continues through the rest of the lines.

He isn't using a different version of IExplorer, because like I said, we have 2 computers in the office that all employees share. He's tried it on both computers and the same thing happens on both computers. Also, I don't think his security settings are different because he's able to manually access the webform and submit the data that way.

Edit: As far as the compiling error goes, my guess would be that I have both the Microsoft Internet Controls and Microsoft HTML Object Library references selected (Can't remember exactly which one it is that's needed for InternetExplorerMedium). Do you have those selected?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top