Xuân Thanh > 22-04-13, 05:05 PM
Option Compare Database
Option Explicit
Function ImportTable(strNguon As String, strTabNguon As String, strTabDich As String)
Dim DBNguon As Database
Dim DBDich As Database
Dim rsNguon As Recordset
Dim rsDich As Recordset
Set DBNguon = DBEngine.Workspaces(0).OpenDatabase(strNguon)
Set DBDich = CurrentDb
Set rsNguon = DBNguon.OpenRecordset(strTabNguon)
Set rsDich = DBDich.OpenRecordset(strTabDich)
Dim i As Integer
If rsNguon.RecordCount > 0 Then
rsNguon.MoveFirst
Do Until rsNguon.EOF
rsDich.AddNew
For i = 0 To rsNguon.Fields.Count - 1
rsDich.Fields(i) = rsNguon.Fields(i)
Next
rsDich.Update
rsNguon.MoveNext
Loop
End If
rsNguon.Close: rsDich.Close: Set DBNguon = Nothing: Set DBDich = Nothing
End Function
Function GetFile(Tit As String, formatName As String, formatType As String)
Dim dlgOpen As FileDialog
Dim result
Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
With dlgOpen
.Title = Tit
.Filters.Clear
.Filters.Add formatName, formatType
.AllowMultiSelect = False
result = .Show
If (result <> 0) Then
GetFile = Trim(dlgOpen.SelectedItems.Item(1))
End If
End With
End Function
Option Compare Database
Option Explicit
Private Sub cmdTim_Click()
Me.txtTenFile = GetFile("C:\", "Select File", "*.mdb,*.mde")
End Sub
Private Sub cmdImport_Click()
Call ImportTable(Me.txtTenFile, Me.txtTableNguon, txtTableDich)
End Sub
ndthanh29 > 21-07-14, 06:36 PM
k2d_nh0k > 23-03-21, 05:31 PM
k2d_nh0k > 23-03-21, 05:32 PM