From VB, check if runtime or full Access

S

SimeonD

Hi
From a visual basic program, I want to check if a user has the runtime or
full version of Access.
How would I do this?
Thanks
Simeon
 
S

SimeonD

Its a Visual Basic Dotnet program that I'm using.
How would I run Syscmd from Dotnet?
 
F

Family Tree Mike

SimeonD said:
Hi
From a visual basic program, I want to check if a user has the runtime or
full version of Access.
How would I do this?
Thanks
Simeon


I would think this line of code would fail with the runtime version, but be
fine with the full version:

Dim o As Object = CreateObject("Access.Application")
 
D

Douglas J. Steele

If you're running a program, why do you care whether the user has the
runtime or the full version?
 
S

SimeonD

I want to lauch Access from my Vb.net program. Not get at the Access data -
actually open the Access frontend.
So I need to something like:
MSAccess.exe "MyDB.mdb"
I can get the path to Access, I found some code on the Microsoft site, which
I have posted below.
I need to know if the user has the full version - otherwise many of the
dotnet access interop functions will fail.
For example, Dim oAccess As Access.Application won't work unlesss full
access is present.
Users will full version of access will get more functionality from my
program. Runtime users will get all the features, as the Office.Interop
won't work.



'**********************************************
Public Function GetOfficeAppPath(ByVal sProgId As String, ByVal sEXE As
String) As String
'Returns path of the Office application. e.g.
'GetOfficeAppPath("Access.Application", "msaccess.exe") returns
'full path to Access. Approach based on Q240794.
'Returns empty string if path not found in registry.

' Enable an error handler for this procedure:
On Error GoTo ErrorHandler

Dim oReg As Microsoft.Win32.RegistryKey = _
Microsoft.Win32.Registry.LocalMachine
Dim oKey As Microsoft.Win32.RegistryKey
Dim sCLSID As String
Dim sPath As String
Dim iPos As Integer

' First, get the clsid from the progid from the registry key
' HKEY_LOCAL_MACHINE\Software\Classes\<PROGID>\CLSID:
oKey = oReg.OpenSubKey("Software\Classes\" & sProgId & "\CLSID")

sCLSID = oKey.GetValue("")
oKey.Close()

' Now that we have the CLSID, locate the server path at
' HKEY_LOCAL_MACHINE\Software\Classes\CLSID\
' {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx}\LocalServer32:
oKey = oReg.OpenSubKey("Software\Classes\CLSID\" & sCLSID &
"\LocalServer32")
sPath = oKey.GetValue("")
oKey.Close()

' Remove any characters beyond the exe name:
iPos = InStr(1, sPath, sEXE, CompareMethod.Text)
sPath = Microsoft.VisualBasic.Left(sPath, iPos + Len(sEXE) - 1)
Return Trim(sPath)
ErrorHandler:
Return ""
End Function
 
D

Douglas J. Steele

I believe Automation of the run-time will work, but only if Access is
already open. In other words, I believe

Dim oAccess As Access.Application

should still work, but

Set oAccess = New Access.Application

won't, which, in DotNet terms, means you can't declare as

Dim oAccess As New Access.Application

I haven't use DotNet that much, but I believe it still has the Shell
statement in it. Use Shell to start Access, then use GetObject to set the
reference.
 
F

Family Tree Mike

Douglas J. Steele said:
I believe Automation of the run-time will work, but only if Access is
already open. In other words, I believe

Dim oAccess As Access.Application

should still work, but

Set oAccess = New Access.Application

won't, which, in DotNet terms, means you can't declare as

Dim oAccess As New Access.Application

I haven't use DotNet that much, but I believe it still has the Shell
statement in it. Use Shell to start Access, then use GetObject to set the
reference.


Using early binding, you are tied to the particular version of Access. You
need to add a reference into your project, so you are tied to the version on
your machine. For this reason, you should use late binding to test as I
said in an earlier post. To do this use:

Dim o As Object = CreateObject("Access.Application")

This only succedes if a full version of access available.
 
D

Douglas J. Steele

Family Tree Mike said:
Using early binding, you are tied to the particular version of Access.
You need to add a reference into your project, so you are tied to the
version on your machine. For this reason, you should use late binding to
test as I said in an earlier post. To do this use:

Dim o As Object = CreateObject("Access.Application")

This only succedes if a full version of access available.

Have you tried using Shell to open the runtime, and then using GetObject, as
I suggested?

Dim o As Object

' Use Shell here...

o = GetObject(, "Access.Application")
 
F

Family Tree Mike

Douglas J. Steele said:
Have you tried using Shell to open the runtime, and then using GetObject,
as I suggested?

Dim o As Object

' Use Shell here...

o = GetObject(, "Access.Application")


You don't need a running instance of Acces to get the object. Just use
automation.
 
F

Family Tree Mike

Douglas J. Steele said:
Even you said "This only succedes if a full version of access available."

I believe you do need a running instance of Access in order to use
Automation with the run time. See, for example,
http://support.microsoft.com/?id=296586


Yes, that is what I said, as to the original question of how do you test if
the full applicaiton MS Access is installed. That code is the test. If
that code fails, you don't have MS Access. You do not need to start MS
Access to run that line of code however, if you have MS Access installed.
 
F

Family Tree Mike

Family Tree Mike said:
Yes, that is what I said, as to the original question of how do you test
if the full applicaiton MS Access is installed. That code is the test.
If that code fails, you don't have MS Access. You do not need to start MS
Access to run that line of code however, if you have MS Access installed.


Here is a complete source example to test for MS Access from VB.Net. If you
have it, an instance will be started and visible with no DB, and an
approprate message listed. The catch should take care of an error showing
no copy of MS Access, therefore creating an error in the CreateObject
function.

Module Module1

Sub Main()
Try
Dim o As Object = CreateObject("Access.Application")
o.Visible = True
Console.Out.WriteLine("You have full MS Access")
Catch ex As Exception
Console.Out.WriteLine("You appear to not have MS Access
installed.")
End Try
Console.In.ReadLine()
End Sub

End Module
 
S

SimeonD

Here is a complete source example to test for MS Access from VB.Net. If
you have it, an instance will be started and visible with no DB, and an
approprate message listed. The catch should take care of an error showing
no copy of MS Access, therefore creating an error in the CreateObject
function.

Module Module1

Sub Main()
Try
Dim o As Object = CreateObject("Access.Application")
o.Visible = True
Console.Out.WriteLine("You have full MS Access")
Catch ex As Exception
Console.Out.WriteLine("You appear to not have MS Access
installed.")
End Try
Console.In.ReadLine()
End Sub

End Module

@doug - I have no problem opening runtime Access, I'm using the Shell
command myself, with some code from
http://msdn.microsoft.com/en-us/library/aa167790(office.11).aspx

@mike - Thanks. However, there are two problems here:
1) If the version of Access is not 2003, this code will incorrectly treat it
as not having the full version of Access.

2) Also, if there is no Access at all installed, how would I know?

I wonder how Tonys AutoFE program works, that always seems to use the
correct version of access. Hmm, must give that a quick look.
Thanks for the help so far,
Simeon
 
F

Family Tree Mike

SimeonD said:
@Mike - Thanks. However, there are two problems here:
1) If the version of Access is not 2003, this code will incorrectly treat
it as not having the full version of Access.

2) Also, if there is no Access at all installed, how would I know?

I wonder how Tonys AutoFE program works, that always seems to use the
correct version of access. Hmm, must give that a quick look.
Thanks for the help so far,
Simeon

1) I only have 2003, but why do you say that this only works for 2003? You
are not tied to a version unless you add a reference to MS Access objects.
2) If there is no Access at all, then you handle that fact in the catch,
however you want your application to handle this condition. If you wanted a
bool function to test for existance, the code given could be modified to
return false inside the catch, but true otherwise.
 
S

SimeonD

I say it only works for 2003, as I've tested the code you sent on an XP and
a 2000 PC. :)
I think that VB.net assumes 2003, whether late binding or not.
Dim o As Object = CreateObject("Access.Application") is creating an Access
2003 object, which fails. It does seem to be a 'generic' access object.

Now that I think about it, using the MS code I can find the path to
MSAccess. If that path isn't present, I know there is no access on the PC.

But I still don't know how to find if its the runtime!
 
F

Family Tree Mike

SimeonD said:
I say it only works for 2003, as I've tested the code you sent on an XP and
a 2000 PC. :)
I think that VB.net assumes 2003, whether late binding or not.
Dim o As Object = CreateObject("Access.Application") is creating an Access
2003 object, which fails. It does seem to be a 'generic' access object.

That is not my experience. Sorry, I don't know how to help you.
 

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