Dymondjack said:
Thanks Dirk, this is exactly what I was looking for.
After posting that, I decided that it might come in handy for me, too, so I
wrote the function below to use the ShellWait and fFindExe functions (from
the links posted) to open a document and wait for it to be closed:
'----- start of code -----
Function fOpenDocAndWait( _
pstrDocPath As String, _
Optional plngWindowStyle As Long = WIN_NORMAL) _
As Long
' Written by: Dirk Goldgar, DataGnostics LLC
' Feel free to use this in your own applications, but I'd appreciate
' your not selling it separately.
On Error GoTo Err_Handler
Dim strFileName As String
Dim strFolder As String
Dim strExePath As String
Dim strCommandLine As String
Const Q As String = """"
strFileName = Dir(pstrDocPath)
If Len(strFileName) = 0 Then
fOpenDocAndWait = 53 ' File not found
Exit Function
End If
strFolder = Left$(pstrDocPath, Len(pstrDocPath) - Len(strFileName))
strExePath = _
Trim(Replace(fFindEXE(strFileName, strFolder), Chr(0), " "))
If Len(strExePath) = 0 Then
fOpenDocAndWait = 17 ' Can't perform requested operation
ElseIf strExePath Like "Error:*" Then
fOpenDocAndWait = 17 ' Can't perform requested operation
Else
strCommandLine = Q & strExePath & Q & " " & Q & pstrDocPath & Q
ShellWait strCommandLine, plngWindowStyle
fOpenDocAndWait = 0
End If
Exit_Point:
Exit Function
Err_Handler:
fOpenDocAndWait = Err.Number
Resume Exit_Point
End Function
'----- end of code -----
Just out of
curiousity, for anyone who would like to answer, what type of performance
effects do API's have on an access db? I'm gathering quite the collection
as
I progress, between filepickers, opening files, testing server
connections,
manipulating the access window, ect ect...
In my opinion, the API call will generally be at least as fast, and usually
faster than doing something similar using built-in methods, because either
the built-in method will be a wrapper around the API call, or else will
involve more elaborate programming with the overhead of using code objects
and loops that would otherwise not be required.
I tend to write code for the majority of things that my application does,
I
prefer not to let access make it's own descisions where I don't have to,
but
even for the 7000+ lines of code I have, API's seem to have a massive
amount
of arguments compared to general VB funtions. So far I haven't noticed
any
major performance issues, but being new to this, I have no idea how much
memory the system can use before it starts to become an issue.
I will normally use a built-in function or feature where it's available and
its performance is at least close to that of a corresponding API call, just
because it is better documented. Also, not all API calls are available on
all versions of the operating system (though as older OS versions are fading
from use, this is less of a concern). But I'll use an API call in
preference to an ActiveX control, because those generally require specific
references to be set, and are vulnerable to broken references, versioning
problems, and distribution/licensing issues.