Attribute VB_Name = "modDB"
Option Explicit

Public Function GetDBVersion(oDB As ADODB.Connection, _
                Optional sColumnName As String = "nDBVersion", Optional sTableName As String = "DBInfo") As Long

9           Dim i As Long
10          Dim rstTmp As ADODB.Recordset
11          Dim bFound As Boolean
12
13          'Now we setup error checking for trying to read the version
14          Set rstTmp = OpenMyRecordset(oDB, "SELECT " & sColumnName & " FROM " & sTableName)
15
16          bFound = False
17          For i = 0 To rstTmp.Fields.Count
18              If rstTmp.Fields(i).Name = sColumnName Then
19                  GetDBVersion = rstTmp![nDBVersion]
20                  bFound = True
21                  Exit For
22              End If
23          Next i
24          If bFound = False Then
25              Call Err.Raise(-1, "GetDBVersion", "Unable to locate " & sColumnName & " in " & sTableName & ".  Ordinal referance failed.")
26          End If
27
28                                                                                                                              '<RIVERWATCH_ADDER>
29                                                                                                                              '<RIVERWATCH_ADDER>
End Function

Public Function OpenDB(sFileName As String) As ADODB.Connection
8
9           Dim sConnectionString As String
10          Dim rstTmp As ADODB.Recordset
11          Dim nUpgradeFrom As Long
12          nUpgradeFrom = 1
13          Set OpenDB = New ADODB.Connection
14
15          'Ok this gets confusing....  First of all we will try to open the DB as a Jet 3.51 DB.
16          On Error GoTo Jet351_Failed
17          'Try to open it
18          sConnectionString = "Provider=Microsoft.JET.OLEDB.3.51;Data Source=" & sFileName
19          Call OpenDB.Open(sConnectionString)
20          'We only get to this goto if the open command worked
21          GoTo DBOpened
22          'Oops, this means we got an error
23 Jet40:
24          'Setup a normal error handler so if an error happens we don't jump back to Jet 4.0
25          On Error GoTo 0 'Jet40_Failed
26          'Now try to open the DB with Jet 4.0
27          sConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & sFileName
28          Call OpenDB.Open(sConnectionString)
29
30          'Yea we got the damn db open!
31 DBOpened:
32
33          Exit Function
34 Jet351_Failed:
35          If Err.Number = 3706 Then 'This is the provider not found message.
36              GoTo Jet40
37          Else
38              Call Err.Raise(Err.Number, Err.Source, Err.Description)
39          End If
40
End Function

Public Function OpenMyRecordset(dbDatabase As ADODB.Connection, sSQL As String) As ADODB.Recordset
8
9           Dim oRSetReturn As New ADODB.Recordset
10
11          oRSetReturn.CursorLocation = ADODB.adUseClient
12          oRSetReturn.CursorType = ADODB.adOpenKeyset
13
14          oRSetReturn.LockType = ADODB.adLockOptimistic
15          Call oRSetReturn.Open(sSQL, dbDatabase, oRSetReturn.CursorType, ADODB.adLockUnspecified, ADODB.adCmdText)
16          Set OpenMyRecordset = oRSetReturn
17
End Function
