Hmm the error handler works now but when it triggers an error it doesn't stop sending emails
here is the entire code
On Error Resume Next
Begintime = Now()
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, drivername, servername from " _
& " 'LDAP://DC=tke,DC=intra' where objectClass='printQueue'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
If Err.Number<>0 Then
MyErrorHandler
End If
arrPrinter = objRecordSet.GetRows()
objConnection.Close()
iprinterCount = 0
Set MyConnection = CreateObject("ADODB.Connection")
'SQL Connection String
MyConnection.Open "Driver={SQL Server};server=(local);database=IPBD_TEST;uid=SA;pwd=;"
'MyConnection.Open "Driver={SQL Server};server=bla;database=IPBD_TEST;uid=SA;pwd=;" 'this (servername) triggers the error
If Err.Number<>0 Then
MyErrorHandler
End If
Set CreateAllCommand = CreateObject("ADODB.Command")
Set CreateAllCommand.ActiveConnection = MyConnection
Set TruncateAllCommand = CreateObject("ADODB.Command")
Set TruncateAllCommand.ActiveConnection = MyConnection
'creation das SQL befehl
CreateAllCommand.CommandType = 1
CreateAllCommand.CommandText = "INSERT INTO [printerTemp] ([Printername], [servername], [description] VALUES(?,?,?)"
'empty table before refilling it
TruncateAllCommand.CommandType = 1
TruncateAllCommand.CommandText = "TRUNCATE TABLE [PrinterTemp]"
TruncateAllCommand.Execute
For intI = 0 to UBound(arrPrinter,2)
strServerName = Trim(arrPrinter(0, IntI))
strDrivername = Trim(arrPrinter(1, IntI))
strPrinterName = Trim(arrPrinter(2, IntI))
strSQLCreate = "INSERT INTO [printerTemp] ([Printername], [servername], [description]) "
strSQLCreate = strSQLCreate & "VALUES ('" & strPrinterName & "', '" & strServerName & "', '" & strDrivername & "')"
CreateAllCommand.CommandText = strSQLCreate
CreateAllCommand.Execute
If Err.Number<>0 Then
MyErrorHandler
End If
iprinterCount = iprinterCount + 1
Next
MyConnection.Close()
'MsgBox Begintime & vbcrlf & Endtime
'MsgBox iprinterCount
Sub MyErrorHandler()
emailserver = "bla"
meldung = "an error has occured in on the sql serversql script was not succesfull"
meldung = meldung & vbcrlf & "test"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "some email"
objEmail.To = "some emil"
objEmail.Subject = "ES-APPL-LD: Synchronisation printers was not successfull"
objEmail.Textbody = meldung
objEmail.Configuration.Fields.Item _
("
= 2
objEmail.Configuration.Fields.Item _
("
= emailserver
objEmail.Configuration.Fields.Item _
("
= 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub