Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 13th, 2005, 04:04 AM
Me
Guest
 
Posts: n/a
Default Determine and MDB file's Access version without opening it?

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.
  #2  
Old November 13th, 2005, 04:04 AM
Eric Schittlipz
Guest
 
Posts: n/a
Default Re: Determine and MDB file's Access version without opening it?


"Me" <heruti@lycos.com> wrote in message
news:2d4c3262.0409200303.15107319@posting.google.c om...[color=blue]
> 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.[/color]





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










 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles