View Full Version : object required


jasn_78
03-18-2008, 03:55 PM
hey guys i get an object required on set mac = for the below code

Private Sub txtSERIAL_GotFocus()

Dim oWMIService As Object
Dim oColAdapters As Object
Dim oObjAdapter As Object
Dim mac As String
Dim y As Double
Dim z As Integer


Set oWMIService = GetObject("winmgmts:" & "!\\.\root\cimv2")
Set oColAdapters = oWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each oObjAdapter In oColAdapters
Next

Set mac = oColAdapters

For y = 1 To Len(mac)

If IsNumeric(Mid(mac, y, 1)) Then
z = z & Mid(mac, y, 1)
End If


Next y

Me.txtSERIAL = y

Set oObjAdapter = Nothing
Set oColAdapters = Nothing
Set oWMIService = Nothing

End Sub

any suggestions?

ajetrumpet
03-18-2008, 04:45 PM
Some notes...




Private Sub txtSERIAL_GotFocus()

Dim oWMIService As Object
Dim oColAdapters As Object
Dim oObjAdapter As Object
Dim mac As String <---- variable is a STRING
Dim y As Double
Dim z As Integer


Set oWMIService = GetObject("winmgmts:" & "!\\.\root\cimv2")
Set oColAdapters = oWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each oObjAdapter In oColAdapters
Next

Set mac = oColAdapters <---Drop the SET statement here (i.e. - "mac = oColAdapters") SET is for objects

For y = 1 To Len(mac)

If IsNumeric(Mid(mac, y, 1)) Then
z = z & Mid(mac, y, 1)
End If


Next y

Me.txtSERIAL = y

Set oObjAdapter = Nothing
Set oColAdapters = Nothing
Set oWMIService = Nothing

End Sub

any suggestions?

jasn_78
03-18-2008, 04:59 PM
thanks for ur advice there adam

didnt know that bout strings

ajetrumpet
03-18-2008, 05:03 PM
Not a problem. Good luck...

Think of the SET statement as something that needs to be associated with heavy things, like objects... strings are not heavy. :)