objWMIService

ddrew

seasoned user
Local time
Today, 23:23
Joined
Jan 26, 2003
Messages
911
I have a piece of code running in a form that idenifys the name of the PC that it is on. I currenly run it on 12 different machines and it works on them all, except one. The code I'm running is:

Code:
Private Sub Form_Load()
Dim objWMIService As Object
Dim colAdapters As Object
Dim strComputer As String
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1
For Each objAdapter In colAdapters
    'Me.Text0 = objAdapter.MACAddress
    If Not IsNull(objAdapter.IPAddress) Then
        For I = 0 To UBound(objAdapter.IPAddress)
            Me.Text1 = objAdapter.IPAddress(I)
        Next
    End If
n = n + 1
Next



If Me.Text1 = "3.3.12.8" Then
    Me.OCANo = "OCA 1 MCC"
End If
If Me.Text1 = "9.0.0.244" Then
    Me.OCANo = "OCA 1 AAR"
End If
If Me.Text1 = "3.3.13.8" Then
    Me.OCANo = "OCA 2 MCC"
End If
If Me.Text1 = "3.3.14.8" Then
    Me.OCANo = "OCA 3 MCC"
End If
If Me.Text1 = "3.3.15.8" Then
    Me.OCANo = "OCA 4 MCC"
End If
If Me.Text1 = "3.3.16.8" Then
    Me.OCANo = "OCA 5 MCC"
End If
If Me.Text1 = "3.3.17.8" Then
    Me.OCANo = "OCA 6 MCC"
End If
Me.Exercise_Date = Now()
End Sub

The error I'm getting is on the line
Code:
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Its only happening on one machine, anyone help on this please?
 
The first thing to think about when code runs on one machine but not another is that the errant machine has a missing library reference. That's what I'd check for first.
 
Agreed, WMI doesn't come installed on every machine.
 
Thanks for your help, I thought it maybe something like that! This might sound daft but is it part of access of something totaly different. Incidentaly the problem is solved as we have just taken delivery of new PCs with upgrades to Vista and Access 07 and it works fine on all machines.

However I would still be interested to know how to install/enable that application?
 
Not part of Access. I've used it before but don't know enough to answer specific questions. You can do a LOT more with it than you're doing. There is a nice writeup on MSDN.
 

Users who are viewing this thread

Back
Top Bottom