Acces ODBC passthru query fails with error 3146 giving different error description texts - postgresql

I create a passthru query SELECTINg rows of a Postgres v.11 database table.
Running currentDb.execute generates ODBC error 3146 and "invalid argument" mentioned in DBEngine.errors.
Opening same query in the database explorer generates ODBC error 3146 and a message box with "permission denied ..." which actually reflects the source of error.
My questions is how can I programmatically get hold of latter more informative error message ?

I think the following will provide what you are looking for:
Public Function DbEngineErrors() As String
Dim intErr As Integer
Dim strRet As String
Dim strErr As String
If DBEngine.Errors.Count > 0 Then
strRet = "DbEngineErrors:"
For intErr = 0 To DBEngine.Errors.Count - 1
strErr = DBEngine.Errors(intErr).Number & " / " & DBEngine.Errors(intErr).Description & " / " & DBEngine.Errors(intErr).Source
strRet = strRet & vbCrLf & strErr
Next
End If
DbEngineErrors = strRet
End Function

Related

Not getting incident reference number when I run a vbscript

I'm trying to retrieve a incident reference number when I run a vbscript. The script opens the ticket with the script ticket values in the code but it returns the following error: Error: Necessary object: 'oWSResponseDoc.selectSingleNode(...)'
The code I am using is
' Perform the insert and check the status
If Not wsInsertIncident.Post Then
WScript.Echo "Error=" & wsInsertIncident.Status
WScript.Echo wsInsertIncident.StatusText
WScript.Quit
End If
Dim strIncidentSysId, strIncidentNumber
strIncidentSysId = wsInsertIncident.GetValue("sys_id")
strIncidentNumber = wsInsertIncident.GetValue("number")
WScript.Echo "Inserted: " & strIncidentNumber
I know this worked in the past but today it doesn't. I don't know what has changed. Full script can be seen here:
https://servicenowsoap.wordpress.com/2013/10/26/vb-script/
Can you please help me? Many thanks!
You need to use the SetMethod function before you can insert an incident. This is used to determine what action to take when you make the web call.
I tested this on a demo instance and it created the incident and returned a number.
' Specify the ticket values
Dim wsInsertIncident : Set wsInsertIncident = New ServiceNowDirectWS
wsInsertIncident.SetMethod "incident", "insert"
wsInsertIncident.SetValue "short_description", "Demo WS Incident"
wsInsertIncident.SetValue "description", "Demo WS Incident"
wsInsertIncident.SetValue "caller_id", "Abel Tuter"
wsInsertIncident.SetValue "category", "hardware"
wsInsertIncident.SetValue "subcategory", "mouse"
' Perform the insert and check the status
If Not wsInsertIncident.Post Then
WScript.Echo "Error=" & wsInsertIncident.Status
WScript.Echo wsInsertIncident.StatusText
WScript.Quit
End If
Dim strIncidentSysId, strIncidentNumber
strIncidentSysId = wsInsertIncident.GetValue("sys_id")
strIncidentNumber = wsInsertIncident.GetValue("number")
WScript.Echo "Inserted: " & strIncidentNumber
Dim objShell : Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.Popup "Inserted: " & strIncidentNumber,, "ServiceNow ticket!"

Why is this block of code producing runtime error 91

This block of code is causing runtime error 91 or with block not set error
this code is for opening reports in crystal report in vb6
For DocCodeCount = 0 To cboDoctorsCode.ListCount - 1
strReportTitle = "DOCTOR'S TRANSMITTAL COPY"
strSqlStatement = "PFMS '" & cboControlCode.Text & "', '" & cboDoctorsCode.List(DocCodeCount) & "', '" & sCurrentUserName & "'"
strFilename = App.Path & "\Reports\ClaimsBillProc\PF MS.rpt"
newRpt.OpenReport vADOConnection, strSqlStatement, strFilename, strReportTitle, 3, False
Set newRpt = Nothing
Next
When used in 1 time opening of report it runs fine but when it is used in this manner in the loop it causes error.
The answer is quite clear: You destroy your object within the loop.
This line is the obvious reason for your one time wonder:
Set newRpt = Nothing

Excel will not close processes

So, I'm using (after modification) this code, from here: How to set recurring schedule for xlsm file using Windows Task Scheduler
My error: Runtime error: Unknown runtime error.
I've searched far and wide to find an way to close the Excel process, but almost everybody uses .Quit sadly it gives the above error. I've also tried .Close, but that is not recognized
' Create a WshShell to get the current directory
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
' Create an Excel instance
Dim myExcelWorker
Set myExcelWorker = CreateObject("Excel.Application")
' Disable Excel UI elements
myExcelWorker.DisplayAlerts = False
myExcelWorker.AskToUpdateLinks = False
myExcelWorker.AlertBeforeOverwriting = False
myExcelWorker.FeatureInstall = msoFeatureInstallNone
' Tell Excel what the current working directory is
Dim strSaveDefaultPath
Dim strPath
strSaveDefaultPath = myExcelWorker.DefaultFilePath
strPath = "C:\Users\hviid00m\Desktop"
myExcelWorker.DefaultFilePath = strPath
' Open the Workbook specified on the command-line
Dim oWorkBook
Dim strWorkerWB
strWorkerWB = strPath & "\Status Report (Boxplots) TEST.xlsm"
Set oWorkBook = myExcelWorker.Workbooks.Open (strWorkerWB, , , , , , True)
' Build the macro name with the full path to the workbook
Dim strMacroName
strMacroName = "Refresh"
on error resume next
myExcelWorker.Run strMacroName
if err.number <> 0 Then
WScript.Echo "Fejl i macro"
End If
err.clear
on error goto 0
oWorkBook.Save
' Clean up and shut down
' Don’t Quit() Excel if there are other Excel instances
' running, Quit() will shut those down also
myExcelWorker.Quit <--- ERROR
Set oWorkBook = Nothing
Set myExcelWorker = Nothing
Set WshShell = Nothing
Found some code on a different side.
The reason why (as far as I understood) is that .Quit and .Close is for VBA not VBS.
' Clean up and shut down
' Don’t Quit() Excel if there are other Excel instances
' running, Quit() will shut those down also
Dim objWMIService, objProcess, colProcess
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & "'EXCEL.EXE'")
For Each objProcess in colProcess
objProcess.Terminate()
Next`
Set oWorkBook = Nothing
Set myExcelWorker = Nothing
Set WshShell = Nothing

Text Emailing using VBscript

I have tried the following code, No errors thrown. and no emails have been sent either.
Dim i, objEmail
' Use custom error handling
On Error Resume Next
Set objEmail = CreateObject( "CDO.Message" )
' Fill in the field values
With objEmail
.From = "xyz#abc.com"
.To = "pqr#abc.com"
.Subject = "Test"
.TextBody = "Email from VB Script"
If mySMTPPort = "" Then
mySMTPPort = 25
End If
With .Configuration.Fields
.Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ) = 2
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ) = "HostNameHere"
.Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = 25
.Update
End With
.Send
End With
' Return status message
If Err Then
EMail = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear
Else
EMail = "Message sent ok"
End If
' Release the e-mail message object
Set objEmail = Nothing
When I execute this VBS file, It just does nothing at all. Please help me out. I have to send simple text emails from my domain to another domain. Or is there a work around for the task i want to perform?
You're probably getting an error when trying to send mail. However, you have error handling enabled (On Error Resume Next), but your error handler just puts the error information in a variable without actually doing anything with that variable. Adding a line that echoes the variable should provide you with more information about what's going on:
If Err Then
EMail = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear
Else
EMail = "Message sent ok"
End If
WScript.Echo EMail
should provide you with more information about what's going on.
Edit: Apparently you're getting a connection error. There are several possible causes for that. First check that your name resolution works correctly:
nslookup HostNameHere
If the name doesn't resolve either use the IP address in your script or get the name resolution fixed.
Next check if you can connect to port 25 on the remote host, both via name and IP address:
telnet HostNameHere 25
telnet a.b.c.d 25
If you get a result like this:
C:\>telnet HostNameHere 25
Connecting To HostNameHere...Could not open connection to the host, on port 25:
Connect failed
something is blocking your connection. Could be a network firewall, a host-based firewall on the remote host, or the service not listening on port 25 in the first place. Check with your network admins and/or the admin(s) of the mail server.
Your code hides errors. err default property is number. So You say if err.number = 0 (same as false) then error, if err.number not 0 (ie error) everything fine.

How to replace a special character in email body with a value in each row using Excel with VBA to multiple recipients

I am creating an Excel UserForm that creates a separate email for up to 500 recipients.
There are 4 columns on the worksheet: Name(Column A), Email(Column B), Value 1(Column C).
The code uses the For and Next loop style, where r is declared as an Integer (r = 2 To 500) and with the MailItem Object, .To =Cells(r,2).
The issue I have is attempting to incorporate values from a range (Column C) that replace special characters placed in the text box used to create the body of the email.
So if I were to type, Hello, There were ^&^ transactions that failed yesterday. and hit a command button used for "Send", it would send an email to the each email address listed in Column B and replace ^&^ with the value in Column C to each individual email address (each row).
Below is the VBA code as an example. There are a lot of other declared variables that I did not mention of course to keep this inquiry as short as possible.
Dim Signature As String, EmailSensitivity As String, EmailImportance As String
Dim Greeting As String, Punctuation As String, Security As String
Sub SendButton1_Click()
If SubjectText = vbNullString Then
If EmailBody1 = vbNullString Then
MsgBox "Form Incomplete:" & vbCrLf & vbCrLf & _
"No Subject or Email Text.", vbOKOnly
Exit Sub
End If
End If
If SubjectText = vbNullString Then
MsgBox "Form Incomplete:" & vbCrLf & vbCrLf & _
"Please enter Subject.", vbOKOnly
Exit Sub
End If
If EmailBody1 = vbNullString Then
MsgBox "Form Incomplete:" & vbCrLf & vbCrLf & _
"Please enter Email Text."
Exit Sub
End If
If SignatureText1 = vbNullString Then
Continue = MsgBox("Your email contains no signature." & vbCrLf & vbCrLf & _
"Are you sure you wish to proceed?", vbYesNo)
If Continue = vbNo Then
Exit Sub
End If
End If
Dim OutApp As Object, OutMail As Object
Dim r As Integer
Application.ScreenUpdating = False
For r = 2 To 501
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
On Error Resume Next
With OutMail
.Subject = Security & SubjectText.Value
.Body = EmailBody1.Value & vbCrLf & vbCrLf & _
SignatureText1.Value
.To = Cells(r, 2)
.Attachements.Add AttachmentText1.Value
.Importance = EmailImportance
.Sensitivity = EmailSensitivity
.Send
End With
Next r
Set OutApp = Nothing
Application.ScreenUpdating = True
Sheet1.Range("A2:B501").Clear
Continue = MsgBox("You have successfully generated a mass email!" & vbCrLf & vbCrLf & _
"Would you like to generate another email?", vbYesNo)
If Continue = vbNo Then
Application.Quit
End If
End Sub
I am still an amateur, so I'm working on cleaning a lot of unnecessary code, but this inquiry is mainly on replacing the special character with the value listed in each row.
This is my first time actually posting an inquiry on a forum, so please let me know if I am not following the correct procedure as your help is much appreciated.
It might be as simple as this, using the Replace function:
...
With OutMail
.Subject = Security & SubjectText.Value
.Body = Replace(EmailBody1.Value,"^&^",Cells(r, 3)) & _
vbCrLf & vbCrLf & SignatureText1.Value
...
Unrelated to this, but importat: On Error Resume Next means the sending (and any operation after that) will silently fail. This will make future debugging more difficult, frustrating and expensive. You should at least log relevant details about what error occured, and for what row in the sheet. And be sure to re-enable error-checking with on error goto 0 or similar after the part of your program that might fail unexpectedly.