I am using the excel to pull in an access query. I can make it work ok. The problem is I am trying to import a query that if using access asks for a start date and end date. When I try to import this query I get the following error:
Microsoft Query:
Too few parameters. Expected 2.
How do I set the parameters within excel so when I try to pull the data it will work or give me the option of selecting a date range? This is my routine for doing the import in excel: Data, Import External Data, New Database Query.
Thanks for looking!!!
Do the dates connstatly change or are they open to whatever you want to pull through?
Mr MaGoo
Magoo.Inc MMVII
If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post
You could adapat the following code which uses SQL:
If you're familiar with SQL it'll be easy but if not i can try and helpSub DAOAccessToExcel_2() Dim db As Database Dim rs As Recordset Dim intColIndex As Integer Dim myDB As String Dim FieldName As String Dim MyCriteria As String Dim TableName As String 'Change as Necessary for Query String TableName = "tblEmployees" FieldName = "Dept" MyCriteria = "'Despatch'" 'WATCH QUOTES HERE!!!! myDB = "C:\Documents and Settings\D11108\Desktop\Excel VBA Advanced\employees.mdb" Set TargetRange = Range("A1") Set db = OpenDatabase(myDB) Set rs = db.OpenRecordset("SELECT * FROM " & TableName _ & " WHERE " & FieldName & " = " _ & MyCriteria & ";", dbReadOnly) ' filter records ' write field names For intColIndex = 0 To rs.Fields.Count - 1 TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name Next ' write recordset TargetRange.Offset(1, 0).CopyFromRecordset rs Set rs = Nothing db.Close Set db = Nothing End Sub
also you'd probably want to add a reference each one of the two dates so the Code pulls through the right Data.
oh yeah you'll aslo need to ad the reference Microsoft DAO 3.6 Object libarary for it to work
Mr MaGoo
Magoo.Inc MMVII
If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post
The dates will change. I don't know sql either. Would I just have to change some of the references in your code to give it a go? I tried this method:
http://www.dailydoseofexcel.com/arch...-data-queries/
but I don't get this area: Between [Enter a start date] And [Enter an end date]. Thanks for helping.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks