CHECK IF PROGRAM EXISTS BEFORE OPENING

D

Developerme

Using Access 2007. I know how to open the program, but I am having tough time
writing code to check if the program exists on the users computer. I want to
check to see if the user has Office Word, and if so, then open the program.
If not, cancel this step. Anyone have a code for this?
 
P

Piet Linden

Using Access 2007. I know how to open the program, but I am having tough time
writing code to check if the program exists on the users computer. I wantto
check to see if the user has Office Word, and if so, then open the program.
If not, cancel this step. Anyone have a code for this?

I guess you could try to automate something using late binding. If
the application is not installed, you will receive an error message.
If you get the error, then stop running your code.
 
B

biganthony via AccessMonster.com

Hi,

I use the following, (that I found on the web some time ago.)

************************************************************************
If ApplicationInstalled("Word.Application", 11) = False Then
MsgBox "The required version of Microsoft Word has not been found on
your computer.", vbExclamation + vbOKOnly, "Microsoft Word Not Found."
Else
'put your code here to perform task.
EndIf
************************************************************************

The value of 11 in the code above is for Office 2003. Just substitute in the
value for Office 2007. Is it 12?

I then have the following code in a module:

************************************************************************
Option Compare Database
Option Explicit

Public Const ERR_REG_READ As Long = -2147024894

Public Function PathToApplication(progid As String, _
Optional Version As Long = -1) As String

Const rkClsid As String = "HKLM\Software\Classes\{0}{1}\CLSID\"
Const rkServerPath As String = "HKLM\Software\Classes\CLSID\{0}\
LocalServer32\"

Dim strVersion As String
Dim strArg As String
Dim strResponse As String

'use early binding and set a reference to Windows Script Host Object
Model.
'for late binding, comment out the following line.
'Dim objShell As New IWshRuntimeLibrary.WshShell
'use late binding.
'for early binding coment out the following two lines.
Dim objShell As Object
Set objShell = CreateObject("wscript.shell")
On Error GoTo Err_Handler:
'If we passed a version value, create a version
'string we can pass to StringFormat (if no
'version value is passed, strVersion will remain
'empty and StringFormat will omit the version
'information
If Version <> -1 Then strVersion = "." & CStr(Version)
'expand the tokens and search for the registry key
strArg = StringFormat(rkClsid, progid, Nz(strVersion, vbNullString))
strResponse = objShell.RegRead(strArg)
If strResponse <> vbNullString Then
strArg = StringFormat(rkServerPath, strResponse)
strResponse = objShell.RegRead(strArg)
End If
'some servers are registered with arguments
'(/automation, etc); remove the arguments
If InStr(strResponse, "/") > 0 Then
strResponse = Trim$(Mid$(strResponse, 1, InStr(strResponse, "/") - 1))

End If

Cleanup:
Set objShell = Nothing

Terminate:
PathToApplication = strResponse
Exit Function

Err_Handler:
Select Case Err.Number
Case ERR_REG_READ:
PathToApplication = vbNullString
Case Else:
MsgBox Err.Description, vbCritical, Err.Number
End Select

'set an empty response string
strResponse = vbNullString
Resume Cleanup:

End Function

Public Function ApplicationInstalled(progid As String, _
Optional Version As Long = 0) As Boolean

'comment out the following line if you wnat to use early binding.
Dim fso As Object

'uncomment the following lines if using early binding above.
'Dim fso As New IWshRuntimeLibrary.FileSystemObject
'Dim fso As New objShell.FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
ApplicationInstalled = fso.FileExists(PathToApplication(progid, Version))

Cleanup:
Set fso = Nothing

End Function

Public Function StringFormat(fmtString As String, ParamArray args() As
Variant) As String

Dim i As Long
Dim strReturn As String

strReturn = fmtString
For i = LBound(args) To UBound(args)
strReturn = Replace(strReturn, "{" & i & "}", args(i))
Next i

Terminate:
StringFormat = strReturn

End Function
*********************************************************************************

Anthony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top