View Full Version : Pinging IP addresses in Access 2007
comsec
06-08-2012, 06:58 AM
First time posting:
Access 2007: On a form I would like to ping multiple IP addresses located in a table, but instead of opening a command prompt, I would like to have 2 round buttons next to it to either turn green if the ping is successful, red if not.
Does anyone have code for this project?
I'm fairly new to VBA so detailed instructions please.
Thank – you in advance!
Comsec
MacroShadow
06-15-2012, 08:25 AM
Here is some code from HiTechCoach that should get you heading in the right direction:
'Test stub
Sub TestPing()
Dim strComputer As String
strComputer = "<target computer>"
If Not SystemOnline(strComputer) Then
MsgBox "This computer is currently unreachable: " & strComputer, vbOKOnly, "Computer Status"
'....your logic
Else
'...your logic
MsgBox "This computer is Online!", vbOKOnly, "Computer Status"
End If
End Sub 'TestPing
'Determine if device is online
Function SystemOnline(ByVal ComputerName As String)
Dim oShell, oExec As Variant
Dim strText, strCmd As String
strText = ""
strCmd = "ping -n 3 -w 1000 " & ComputerName
Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.Exec(strCmd)
Do While Not oExec.StdOut.AtEndOfStream
strText = oExec.StdOut.ReadLine()
If InStr(strText, "Reply") > 0 Then
SystemOnline = True
Exit Do
End If
Loop
End Function
Perhaps a more eloquent function for multiple connections (no command prompt boxes) is via a WMI method:
Function SystemOnline(ByVal ComputerName As String)
' This function returns True if the specified host could be pinged.
' HostName can be a computer name or IP address.
' The Win32_PingStatus class used in this function requires Windows XP or later.
' Standard housekeeping
Dim colPingResults As Variant
Dim oPingResult As Variant
Dim strQuery As String
' Define the WMI query
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & ComputerName & "'"
' Run the WMI query
Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)
' Translate the query results to either True or False
For Each oPingResult In colPingResults
If Not IsObject(oPingResult) Then
SystemOnline = False
ElseIf oPingResult.StatusCode = 0 Then
SystemOnline = True
Else
SystemOnline = False
End If
Next
End Function
comsec
06-17-2012, 11:23 PM
Hi MacroShadow,
Thank - you! I start playing with the code you sent.
Again, thank -you!
comsec
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.