|
|
Программное создание базы данных (временной) - CreateTempDb (DAO)
Public Sub CreateTempDb(Optional TempFileName As String = "TempDB.accdb")
Dim TempDBPath As String
Dim db As DAO.Database
Dim strDBaseLink As String
Dim l As Long
Dim sTableNameTempalete$, sTableNameLocal$
On Error GoTo CreateTempDb_Err
TempDBPath = CurrentProject.Path & "\" & TempFileName
If Dir(TempDBPath) <> "" Then
Kill TempDBPath
DoEvents
Err.Clear
End If
Set db = DBEngine.CreateDatabase(TempDBPath, dbLangCyrillic, dbVersion120)
strDBaseLink = ";DATABASE=" & TempDBPath
sTableNameTempalete = "00tp_TabelFromExcel"
sTableNameLocal = Mid(sTableNameTempalete, 3)
DoCmd.CopyObject TempDBPath, sTableNameLocal, acTable, sTableNameTempalete
DoCmd.TransferDatabase acLink, "Microsoft Access", TempDBPath, _
acTable, sTableNameLocal, sTableNameLocal
sTableNameTempalete = "00tp_..."
sTableNameLocal = Mid(sTableNameTempalete, 3)
DoCmd.CopyObject TempDBPath, sTableNameLocal, acTable, sTableNameTempalete
DoCmd.TransferDatabase acLink, "Microsoft Access", TempDBPath, _
acTable, sTableNameLocal, sTableNameLocal
CurrentDb.TableDefs.Refresh [REM]'Обновляем список таблиц
Application.RefreshDatabaseWindow
DoEvents
CreateTempDb_Bye:
On Error Resume Next
db.Close
Set db = Nothing
Err.Clear
Exit Sub
CreateTempDb_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"in procedure CreateTempDb", vbCritical, "Error!"
Resume CreateTempDb_Bye
End Sub
|
|