Cavaliere
05-26-2010, 04:25 AM
Hi everyone,
I'm trying to import data from Access table into Excel spreadsheet with the following code:
Private Sub CommandButton1_Click()
Dim dbDate As Date
dbDate = Worksheets("Sheet1").Range("Date").Value
Dim Connection As ADODB.Connection
Dim ResultSet As ADODB.Recordset
Set Connection = New ADODB.Connection
Connection.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = G:\temp\Database1.mdb;"
Set ResultSet = New ADODB.Recordset
ResultSet.Open "SELECT * FROM USDQ WHERE Date='" & dbDate & "'", Connection, , , adCmdText
Worksheets("Sheet1").Range("e2").CopyFromRecordset ResultSet
End Sub
the problem is I cannot figure out date syntax and ...WHERE Date='" & dbDate & "'",... is not working. Date formats in excel and in access are the same. Could you please guide me with it.
Thanks in advance.
I'm trying to import data from Access table into Excel spreadsheet with the following code:
Private Sub CommandButton1_Click()
Dim dbDate As Date
dbDate = Worksheets("Sheet1").Range("Date").Value
Dim Connection As ADODB.Connection
Dim ResultSet As ADODB.Recordset
Set Connection = New ADODB.Connection
Connection.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = G:\temp\Database1.mdb;"
Set ResultSet = New ADODB.Recordset
ResultSet.Open "SELECT * FROM USDQ WHERE Date='" & dbDate & "'", Connection, , , adCmdText
Worksheets("Sheet1").Range("e2").CopyFromRecordset ResultSet
End Sub
the problem is I cannot figure out date syntax and ...WHERE Date='" & dbDate & "'",... is not working. Date formats in excel and in access are the same. Could you please guide me with it.
Thanks in advance.