Combining two Microsoft Access databases into one with a form for choosing between them

So, I am entrusted with working on two identical databases, which are very poorly made. Both are divided into front / rear ends, but have different data.

Is it possible to combine both databases into one and create a form so that the user can choose which "database" they will interact with?

To clarify, the school using these databases has a database for the fall semester and the Spring semester. Both contain exact forms / queries / tables, but specific data is different. for example Maybe the teacher learns 3 classes, but 4 classes in Spring (the database is much more complicated than that). The data structure remains unchanged, but the specific data varies depending on the database.

So, if they need to access the data, they need to open the appropriate database. As a result, they constantly open / close different databases. They just want to use one database and switch between Fall / Spring.

Is it possible?

+3
source share
4 answers

, , , , . , "" , . , , , , , , . "" , , ( ).

, Access , , . , , !

+1

, . , :

  • ThisTableShouldBeChanged true, . .
  • GetConnectionString . Access , : "; DATABASE = path"

, , , . : , , , , , .

ODBC SQL Server . , .

Public Function LinkTables() As Boolean
On Error GoTo HandleError

    Dim tdf As TableDef
    Dim tdfNew As TableDef
    Dim strName As String
    Dim tdfs As TableDefs
    Dim strSource As String
    Dim strConnect As String

    Dim blnThrowErr As Boolean

    Dim arr() As Variant

    Set tdfs = CurrentDb.TableDefs

    Dim intCount As Integer
    Dim i As Integer

    intCount = tdfs.Count

    strConnect = GetConnectionString()

    i = 1

    'Save a copy of the existing table names'
    ReDim arr(tdfs.Count, 2)
    For Each tdf In tdfs
        strName = tdf.Name

        If ThisTableShouldBeChanged(strName) Then
            If tdf.Connect <> "" Then

                strSource = tdf.SourceTableName

                arr(i, 1) = strName
                arr(i, 2) = strSource
                i = i + 1
            End If
        End If
    Next tdf

    tdfs.Refresh

    Dim strNameRep As String

    'Create new linked tables'
    For i = 1 To UBound(arr)

        If arr(i, 1) <> "" Then

            Set tdfNew = New TableDef

            strName = arr(i, 1)

            tdfNew.Name = arr(i, 1)
            tdfNew.SourceTableName = arr(i, 2)
            tdfNew.Connect = strConnect

            strNameRep = strName & "_temp"

            'rename the old table'
            tdfs(strName).Name = strNameRep

            tdfs.Refresh

            tdfs.Append tdfNew

            If Err.Number <> 0 Then

                Debug.Print Err.Description
                 tdfs(strNameRep).Name = strName

                Err.Clear
            Else
                tdfs.Delete strNameRep
            End If

            On Error GoTo HandleError

        End If
    Next i

    tdfs.Refresh
    LinkTables = True

ExitHere:
    Exit Function
HandleError:
    MsgBox Err.Description & " (" & Err.Number & ")"

    LinkTables = False
    Resume ExitHere
End Function
+1

, . , , JointStudents :

SELECT F1, F2, F3 FROM JointStudents WHERE Semester=Forms!PickSem!txtSemester

, , , .

0

, , - ( "" db), - , ( , ).

: SQL . , "" ... , . , , , Fall, Spring Spring Fall, .

, , , Fall , - , "" , .

Given that this question was asked a few months ago, and you are working with the school, you probably either solved the problem somehow, or had to put it aside, but if it is still needed, I can publish VBA which should help.

0
source

Source: https://habr.com/ru/post/1780283/


All Articles