thanhtruong > 04-11-15, 11:42 AM
thanhtruong > 05-11-15, 03:34 PM
ongke0711 > 05-11-15, 11:34 PM
Option Compare Database
Option Explicit
Sub CopyFolder()
'Copy tat ca Files va SubFolder tu Folder "FromPath" den Folder "ToPath".'
'Chu y: Neu Folder "ToPath" da co roi, no se ghi de du lieu.'
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim pTablename As String, FolderPath As String
Dim i As Long
'Ham GetFolder se lay duong dan cua file BE dua vao 1 link table Vi du: "tblUsers"'
pTablename = "tblUsers"
FolderPath = GetBEFolder(pTablename) 'Path se la chuoi bao gom "PWD=...;Database=Duong dan file"'
'Tu dong lay duong dan Folder can backup'
For i = Len(FolderPath) To 1 Step -1
If Mid(FolderPath, i, 1) = "=" Then 'Cat bo chuoi "PWD, DATABSE..."'
FromPath = Right(FolderPath, Len(FolderPath) - i)
Exit For
End If
Next
'Tu dong lay duong dan Folder de sao luu file backup'
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("ToPath", dbOpenSnapshot)
ToPath = rs!ToPath
rs.Close
Set rs = Nothing
'Neu muon moi lan backup, se tao ra folder moi thi dat ten folder voi "dd-mm-yyyy"'
'VD: ToPath = "C:\Users\TenUser\" & Format(Now, "yyyy-mm-dd h-mm-ss")'
If Right(FromPath, 1) = "\" Then FromPath = Left(FromPath, Len(FromPath) - 1)
If Right(ToPath, 1) = "\" Then ToPath = Left(ToPath, Len(ToPath) - 1)
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBoxUni FromPath & "không t" & ChrW(7891) & "n t" & ChrW(7841) & "i !"
Exit Sub
End If
FSO.CopyFolder Source:=FromPath, Destination:=ToPath
MsgBoxUni "Folder " & ChrW(273) & "ã " & ChrW(273) & ChrW(432) & ChrW(7907) & "c sao l" & ChrW(432) & "u " & ChrW(7903) & " " & ToPath
End Sub
Public Function GetBEFolder(pTablename As String) As String
Dim strFullPath As String
Dim i As Long
strFullPath = Mid(DBEngine.Workspaces(0).Databases(0).TableDefs(pTablename).Connect, 11)
For i = Len(strFullPath) To 1 Step -1
If Mid(strFullPath, i, 1) = "\" Then
GetBEFolder = Left(strFullPath, i)
Exit For
End If
Next
End Function
Private Sub Command0_Click()
Call CopyFolder
End Sub
thanhtruong > 07-11-15, 11:16 AM
ongke0711 > 07-11-15, 02:29 PM
thanhtruong > 09-11-15, 08:20 AM
ongke0711 > 09-11-15, 02:32 PM
thanhtruong > 09-11-15, 06:01 PM
(09-11-15, 02:32 PM)ongke0711 Đã viết: - Báo "Không tồn tại" là lỗi không tìm thấy folder chứa file test_be.mdb.
- Table mà bạn sửa tên thành "tblUsers" là table của file test_be.mdb (tên "tblUsers" phải đúng từng chữ).
- Ở file test.mdb bạn import linked table với "tblUsers" ở file test_be.mdb
Nếu không ra bạn up file lên đây tôi xem cho nhanh.
thanhtruong > 12-11-15, 08:23 AM
ongke0711 > 12-11-15, 08:49 AM