Unable to run Module Form Load
I have a module that checks if the network Drive is available and a message appears true or false if available or not, I am using the following code to do this. I can run this module when I open the code when I press F5, but I want to run the module when the form loads.Module name is Module1.
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Sub CheckAllConnections()
ServerOn = ComputerIsOnline("server.mmc.local")
BDrive = CreateObject("scripting.filesystemobject").driveex ists("B")
test = BDrive - 1
ProgramFolder = False
If ServerOn + BDrive = -2 Then
ProgramFolder = Len(Dir("B:\Helpdeskinc\")) > 0
End If
MsgBox ("The Helpdeskinc Share Drive available is " & BDrive _
& Chr(10)), vbInformation
End Sub
Public Function ComputerIsOnline(ByVal strComputerName As String) As Boolean
On Error Resume Next
Kill "C:\Logger.txt"
On Error GoTo ErrorHandler
ShellX = Shell("cmd.exe /c ping -n 1 " & strComputerName & " > c:\logger.txt", vbHide)
lPid = ShellX
lHnd = OpenProcess(&H100000, 0, lPid)
If lHnd <> 0 Then
lRet = WaitForSingleObject(lHnd, &HFFFF)
CloseHandle (lHnd)
End If
FileNum = FreeFile
Open "c:\logger.txt" For Input As #FileNum
strResult = Input(LOF(1), 1)
Close #FileNum
ComputerIsOnline = (InStr(strResult, "Lost = 0") > 0)
Exit Function
ErrorHandler:
ComputerIsOnline = False
Exit Function
End Function
__________________
Brendan Bartley
|