thanhtaiteo
Thành viên mới

- Tham gia
- 25/1/13
- Bài viết
- 35
- Được thích
- 1
Xin chào các anh chị
Hiện tại em cần query 2 field MD và SS từ table Database
Với điều kiện
MD phải là ngày hiện tại thì mới dc lấy . Và ở dữ liệu nguồn thì field này thuộc dạng dd/mm/yyy hh:mm
SS thì chỉ lấy " Xử Lý "
Em viết trên câu này mà hoài ko ra Source = "SELECT * FROM [Database] Where......"
Anh chị nào biết giúp em với
Hiện tại em cần query 2 field MD và SS từ table Database
Với điều kiện
MD phải là ngày hiện tại thì mới dc lấy . Và ở dữ liệu nguồn thì field này thuộc dạng dd/mm/yyy hh:mm
SS thì chỉ lấy " Xử Lý "
Em viết trên câu này mà hoài ko ra Source = "SELECT * FROM [Database] Where......"
Anh chị nào biết giúp em với
Mã:
Option Explicit
Sub getDataFromAccess()
Dim DBFullName As String
Dim Connect As String, Source As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim Col As Integer
Cells.Clear
Set Connection = New ADODB.Connection
DBFullName = "C:\Users\Ostrich\Desktop\student.accdb"
Set Connection = New ADODB.Connection
Connect = "Provider=Microsoft.ACE.OLEDB.12.0;"
Connect = Connect & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Connect
Set Recordset = New ADODB.Recordset
With Recordset
Source = "SELECT * FROM [Database]"
.Open Source:=Source, ActiveConnection:=Connection
For Col = 0 To Recordset.Fields.Count - 1
Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name
Next
Range("A1").Offset(1, 0).CopyFromRecordset Recordset
End With
ActiveSheet.Columns.AutoFit
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
End Sub