Kofax KTM -Delete First page in all the document - kofax

In KTM I have a requirement to delete first page of each document . I am writing below code for the same in batch close event
Private Sub Batch_Close(ByVal pXRootFolder As CASCADELib.CscXFolder, ByVal CloseMode As
CASCADELib.CscBatchCloseMode)
Dim oXDocInfo As CASCADELib.CscXDocInfo
Dim PageIndex As Long
PageIndex = 0
Batch.DeletePage(oXDocInfo, PageIndex)
End Sub
But getting KTM Script error in runtime . Can you please advise where it is going wrong

Related

Bring previous opened window (Word document) to foreground

Suppose I have two hyperlinks (on excel sheet) referring to two documents:
e.g ( A.doc and B.doc ) on my local intranet.
I will open the first document "A.doc" then I will open the second one "B.doc"
The problem:
If there is already an opened word document and then I clicked hyperlink (Word Document on my local intranet),
The later file is not opened automatically and I have to click on the flashing taskbar button to open the cited second file.
This issue occurs only with Microsoft word documents found on my local intranet.
If there is no open document and I clicked on any word hyperlink, It opens normally without any issue.
Please watch this short video to understand my problem.
I need to utilize FollowHyperlink event in excel or any other method to:
bring the previous opened window A.doc to front and then bring the second one B.doc to front.
you may find it a strange question! But I have to do it manually each time to show and bring the second one to front.
I have used this API code (in a Word document) on Normal-ThisDocument:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim LHwnd As Long
Private Sub Document_Open()
If Application.Documents.Count > 1 Then
LHwnd = FindWindow("rctrl_renwnd32", Application.ActiveWindow.Caption)
SetForegroundWindow (LHwnd)
End If
End Sub
And used that code on my excel sheet itself:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
On Error Resume Next
Dim objWd As Object
Set objWd = GetObject(, "Word.Application")
AppActivate objWd.ActiveWindow.Caption
Set objWd = Nothing
End Sub
Finally, I found this helpful page Bring an external application window to the foreground But I could not adapted it to my need.
Please, try the next BeforeDoubleClick event. If the problem is related only to hyperlinks, it should work...
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.column = 1 And Target.Value <> "" Then 'limit this behavior to the first column
If LCase(left(Target.Value, 5)) = "http:" Then
Cancel = True
Dim objWd As Object, d As Object, arrD: arrD = Split(Target.Value, ".")
If LCase(left(arrD(UBound(arrD)), 3)) <> "doc" Then Exit Sub
On Error Resume Next
Set objWd = GetObject(, "Word.Application") 'find the Word open session, if any
On Error GoTo 0
If objWd Is Nothing Then
Set objWd = CreateObject("Word.Application")
End If
With objWd
.Visible = True
Set d = .Documents.Open(Target.Value)
End With
'force somehow the new open document window expose its handler...
Dim i As Long
Do Until objWd.ActiveWindow.Caption = d.name Or _
objWd.ActiveWindow.Caption = left(d.name, InstRev(d.name, ".")-1) & " [Read-Only] [Compatibility Mode]"
i = i + 1: Debug.Print objWd.ActiveWindow.Caption, left(d.name, InstRev(d.name, ".")-1) & " [Read-Only] [Compatibility Mode]"
DoEvents: If i >= 10 Then Exit Do 'just in case, if something unexpected happens...
Loop
SetForegroundWindow CLngPtr(objWd.ActiveWindow.hWnd)
End If
End If
End Sub
It should work in 64 bit, but it is easy to be adapted for both cases, supposing that it works as you need.

How do i get an ODBC refresh to trigger vb code

I have an odbc connection named "Parcel Picks by Hour" that is on an auto run timer every 15 minutes. I want to run an script that sends an email with the updated data after the refresh event is complete. all codes I have found were unsuccessful. since the timer is already built into the ODBC i dont want a code that refreshes the connection then sends an email i just want the refresh to trigger the code to run.
NOT AN ANSWER AN IDEA
Create a class like so, ive called mine clsCustomConnection
Private WithEvents cn As ADODB.Connection
Public Sub Initialise(cnADO As ADODB.Connection)
Set cn = cnADO
End Sub
Private Sub cn_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, _
ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)
' Email function
MyEmailFunction ("VBAEventExample.co.uk")
End Sub
Then in a normal module, something like so
Public CustomADOConnection As clsCustomConnection
Sub setupADOconnection()
Dim ADOConn1 As New ADODB.Connection
' Set up connection
ADOConn1.ConnectionString = ""
ADOConn1.CursorLocation = adUseClient
' Sink to custom connection
Set CustomADOConnection = New clsCustomConnection
CustomADOConnection.Initialise ADOConn1
End Sub

open msaccess as swarm

We all know that ms access is not multitreaded so when msacces runs a long query it hangs waiting to the query to be completed. what i want is open from access an new instance of access to run a query or run vba code in background. after running it needs to kit itself after it turns back the results (maybe though the sql server background)
i have seen something before in excel but i wonder if it is posible to do in access
the excel variant is here [excel swarm][1
UPDate
i open access with the folowing code
Dim appAccess As Object
Set appAccess = CreateObject("Access.Application")
Call appAccess.OpenCurrentDatabase( _ "D:\test.accdb")
appAccess.UserControl = True
Set appAccess = Nothing
the target access db is preformatted with a loop as test with is started when access opens. the problem is that the souce access hangs during starting ans running of the target access.
i can use the timer to give it a delayed start and then its working.
the main problem is how can i stat a not preformated access db, create things like vba code, querys odbc connections etc and run it without the source db being hanging.
you could try something like this from a shell command to another VBA host, say excel, which could trigger the event. This is a class, where the properties of DB path and Query name are passed in, then GO is executed, it uses the Execute Complete event of the DBs ADO connection, I've coded it to create an Excel instance and populate with the results.
Ive not tested this fully as in the middle of something, but i'll test fully at lunch and edit as req'd, but a starting point
Option Explicit
Private WithEvents c As ADODB.Connection
Private strDBPath As String
Private strQueryToRun As String
Public Property Let DBPath(strPath As String)
strDBPath = strPath
End Property
Public Property Let QueryToRun(strQuery As String)
strQueryToRun = strQuery
End Property
Public Function GO()
Dim a As New Access.Application
a.OpenCurrentDatabase strDBPath, False
Set c = a.CurrentProject.Connection
c.EXECUTE strQueryToRun
a.CloseCurrentDatabase
a.Quit
Set a = Nothing
End Function
Private Sub c_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, _
ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)
' what to do with the results?
Dim xl As New Excel.Application
Dim xlWb As Excel.Workbook
xl.Visible = True
Set xlWb = xl.Workbooks.Add
xlWb.Sheets(1).Range("a1").CopyFromRecordset pRecordset
End Sub
Yes, that is possible.
Use command Shell to open another instance of Access - and add command line parameters Access to hold info about which queries to run.

Backing up a document in the background

I know how to create an vs2013 addin for word which automatically saves a document in the background:
this.Application.Documents[#"C:\Test\NewDocument.docx"].Save();
The problem with this is, that if the user is saving the document to:
C:\MyDocument.docx and doesn't realise that the location has changed in the background to C:\Test\NewDocument.docx, they might get confused.
So my question is, is it possible to somehow create a backup of the document in the background in a different location? So the addin automatically keeps saving to C:\Test\NewDocument.docx, but when the user clicks the builtin save function in Word, it saves to where the user thinks it should be saving too.
Is this possible?
Let's first make clear what you are doing
Your
this.Application.Documents[#"C:\Test\NewDocument.docx"].Save();
is not any magic that saves file in the background. It just saves the document into a specific a path (C:\Test) with a specific name {NewDocument.docx). So you simply save document, nothing else.
If you want to make a copy of an existing document and you don't want to force user to save it, you have two options
auto save feature in Word (I don't know how to control that via code)
make a copy of existing file that must be at least once saved
Let's talk about #2, you can easily copy a file from one location to another but the file must be closed. So there is an another approach a functional example is bellow (I don't like accessing Globals directly but for this example is OK)
Public Class ThisAddIn
Dim _myTimer As System.Windows.Forms.Timer
Private Sub ThisAddIn_Startup() Handles Me.Startup
_myTimer = New System.Windows.Forms.Timer
With _myTimer
.Interval = 30000 ' 30 sec
AddHandler .Tick, AddressOf TimerEventOcured
.Start()
End With
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
If _myTimer IsNot Nothing Then _myTimer.Stop()
End Sub
Private Sub TimerEventOcured(ByVal sender As Object, ByVal e As EventArgs)
CopyFile()
End Sub
Private Sub CopyFile()
Const DEST_PATH As String = "c:\"
Const FILE_NAME As String = "BackUp.docx"
Try
Dim currentDoc As Word.Document = Globals.ThisAddIn.Application.ActiveDocument
' was it saved at least once, the full path then contains extension, e.g. dotx
If Not currentDoc.FullName.Contains(".") Then Return
' makes copy of the current document with UNSAVED changes and save it to specified location
Dim backUpCopy As Word.Document = currentDoc.Application.Documents.Add(currentDoc.FullName)
Dim tmpFileNAme As String = System.IO.Path.GetTempFileName.Replace(".tmp", ".dotx")
backUpCopy.SaveAs2(FileName:=tmpFileNAme, AddToRecentFiles:=False)
System.IO.File.Copy(sourceFileName:=tmpFileNAme, _
destFileName:=Path.Combine(DEST_PATH, FILE_NAME), _
overwrite:=True)
' remove the temp files
backUpCopy.Close(SaveChanges:=False)
System.IO.File.Delete(tmpFileNAme)
System.IO.File.Delete(tmpFileNAme.Replace(".dotx", ".tmp"))
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(String.Format("hey, an error here{0} {1}", vbNewLine, ex.Message))
End Try
End Sub
End Class

Set Document ( form ) - EditMode to false

I want to put a form ( document ) to EditMode = false; So, when the form is opened, I want to cannot modify any fields etc until I press a button that puts the doc. in EditMode = true.
My code is smth like this:
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set uidoc = ws.CurrentDocument
'Set doc = uidoc.Document
uidoc.EditMode = False
End Sub
I choose to code in the Initialize method of the Form...
But it doesn't work and it gives me a message like: " Document comand is unavailable" . Please help, I will appreciate, thank you.
As a general rule of thumb, the Initialize event should not be used in forms. One reason for this is that the form has not necessarily finished loading everything by the time that Initialize runs.
This code should be placed in the QueryOpen event.
Another best practice is to NOT use NotesWorkspace.CurrentDocument to get a handle to the current form and instead use the Source parameter passed into the QueryOpen event. NotesWorkspace.CurrentDocument should only be used in agents and other places where the form is not already in context. Calling NotesWorkspace.CurrentDocument while the current document is already in context can cause strange behavior in Notes.
Here's some code that should work:
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
If (Not Source Is Nothing) Then Source.EditMode = False
End Sub

Resources