View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Dave Patrick Dave Patrick is offline
external usenet poster
 
Posts: 249
Default ADO From Excel 2003 to a access.mdb Query

Give this a go.

Public Sub testread()
Dim cnn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim strSQL1 As String, strConn
Dim i As Integer
Dim mydate1 As String
Dim mydate2 As String
mydate1 = Sheets(1).Range("H1")
mydate2 = Sheets(1).Range("H2")
i = 1

'Use for Access (jet)
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Program Files\Microsoft Office\" _
& "Office12\SAMPLES\Northwind.mdb;Persist Security Info=False"

'Use for jet
strSQL1 = "SELECT LastName, FirstName " _
& "FROM Employees " _
& "WHERE (((HireDate) Between #" & mydate1 & "# " _
& "And #" & mydate2 & "#)) " _
& "ORDER BY LastName; "

Set cnn = New ADODB.Connection
Set rs1 = New ADODB.Recordset
cnn.Open strConn
rs1.Open strSQL1, cnn, adOpenForwardOnly, adLockReadOnly
Do While rs1.EOF = False
Sheets("Sheet1").Range("A" & i) = rs1!LastName
Sheets("Sheet1").Range("B" & i) = rs1!FirstName
i = i + 1
rs1.MoveNext
Loop
rs1.Close
cnn.Close
End Sub



--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Mike" wrote:
Im playing around with you Example an got to work with Northwind.
I have tried usining in the Between for mine and no luck Could you tell me
how this needs to be for the Between date for mine.