By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,661 Members | 791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,661 IT Pros & Developers. It's quick & easy.

Determine and MDB file's Access version without opening it?

P: n/a
Me
Hi all,
I have an Access application that has to import hundreds of other
MDB's, some access 97 and some 2000, and merge them into several large
mdb's. so far so good, but my command:

Set appAccess = GetObject(TargetDBPathNAme, "Access.Application.9")

sometimes fails, of course, when the MDB to be imported is Access 97
type.

How do I determine in advance (before GetObject) what version a closed
(unaccessed) MDB is created with?

the best I have come up with, shamefully, was to use "On error"
detection
like this:
<the beginning of the import loop>

OpenImportConnection = true
Set appAccess = GetObject(TargetDBPathNAme, "Access.Application.9")
OpenImportConnection = false
< the error handling section >
If (Err.Number = 7866 Or InStr(1, Err.Description, "Microsoft Access
can't open the database because it is missing") > 0) And
OpenImportConnection Then

' probably trying to open an Access 97 file as an Access 2000 version,
' so switch importing to version 97

Set appAccess = Nothing
Set appAccess = GetObject(TargetDBPathNAme,
"Access.Application.8")
Resume Next

End If

(I got two types of error mesasges occuring because of this).

is there anything better than this, that doesn't depend on
errorhandling?
Thanks for reading.

hh.
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Me" <he****@lycos.com> wrote in message
news:2d**************************@posting.google.c om...
Hi all,
I have an Access application that has to import hundreds of other
MDB's, some access 97 and some 2000, and merge them into several large
mdb's. so far so good, but my command:

Set appAccess = GetObject(TargetDBPathNAme, "Access.Application.9")

sometimes fails, of course, when the MDB to be imported is Access 97
type.

How do I determine in advance (before GetObject) what version a closed
(unaccessed) MDB is created with?

the best I have come up with, shamefully, was to use "On error"
detection
like this:
<the beginning of the import loop>

OpenImportConnection = true
Set appAccess = GetObject(TargetDBPathNAme, "Access.Application.9")
OpenImportConnection = false
< the error handling section >
If (Err.Number = 7866 Or InStr(1, Err.Description, "Microsoft Access
can't open the database because it is missing") > 0) And
OpenImportConnection Then

' probably trying to open an Access 97 file as an Access 2000 version,
' so switch importing to version 97

Set appAccess = Nothing
Set appAccess = GetObject(TargetDBPathNAme,
"Access.Application.8")
Resume Next

End If

(I got two types of error mesasges occuring because of this).

is there anything better than this, that doesn't depend on
errorhandling?
Thanks for reading.

hh.


Function FindVersion(strDbPath As String) As String
Dim dbs As Database
Dim strVersion As String
Const conPropertyNotFound As Integer = 3270

On Error GoTo Err_FindVersion

' Open the database and return a reference to it.
Set dbs = OpenDatabase(strDbPath)

' Check the value of the AccessVersion property.
strVersion = dbs.Properties("AccessVersion")

Debug.Print strVersion
' Return the two leftmost digits of the value of
' the AccessVersion property.
strVersion = Left(strVersion, 2)

' Based on the value of the AccessVersion property,
' return a string indicating the version of Microsoft Access
' used to create or open the database.
Select Case strVersion
Case "02"
FindVersion = "2.0"
Case "06"
FindVersion = "95"
Case "07"
FindVersion = "97"
Case "08"
FindVersion = "2000"
Case "09"
FindVersion = "2002"
End Select

Exit_FindVersion:
On Error Resume Next
dbs.Close
Set dbs = Nothing
Exit Function

Err_FindVersion:
If Err.Number = conPropertyNotFound Then
MsgBox "This database hasn't previously been opened " & _
"with Microsoft Access."
Else
MsgBox "Error: " & Err & vbCrLf & Err.Description
End If
Resume Exit_FindVersion
End Function




Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.