Solved

Excel Access VB - Database pull

Posted on 2012-12-30
5
224 Views
Last Modified: 2012-12-31
I had some VB code that worked well in the past that pulled data from an Access Query into Excel.  After making a few changes in Access, my VB code doesn't appear to work any more.

     With ActiveSheet.QueryTables.Add(connection:=Array( _
        "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin; Data Source = " & dbpath & "\KPI Database_Development_BAIN.mdb; Mode=Sha" _
        , _
        "re Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet " _
        , _
        "OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;J" _
        , _
        "et OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy L" _
        , _
        "ocale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
        ), Destination:=Range("A1"))
        .CommandType = xlCmdTable
        .CommandText = Array("Territory Query")
        .Name = "KPI Database_Development"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceDataFile = dbpath
        .Refresh BackgroundQuery:=False

The last lane regarding the refresh backgroundquery is where the error occur.

The error I get is 'Run Timer Error 1004 Too Few Parameters. Expected 2"
0
Comment
Question by:Golfer219
  • 3
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 38732125
When you get too fee parameter Expected ... this means that you maybe mispelled a field name in your querry and SQL interpret this not as a field but as a parameter and as you did not provide any parameter input then you get this error. the 2 means 2 occurences of this happens.

So you need to ask yourself:
1) Did you change anything in the querry since it was working ?
2) Did you copy it or typed it so it is getting these conflicting results ?
3) Did you change or any field in the database was changed/renamed since it was first working ?

Let me know so we can troubleshoot this further.
gowflow
0
 

Author Comment

by:Golfer219
ID: 38732557
Thanks for helping gowflow!

I did make a few minor changes to field names in the table/query in Access, however I thought that since I only referenced the query name in the VB code, that everything should be OK.  I changed 2 field names in the table and thus the query.

I've included VB code in the past where the code references specific query tables and fields and realized that the code would need to be updated if a field changed, but wasn't aware that there was something I'd need to take into account using the code above.

Any help around this would be greatly appreciated and valued!
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38732595
yes easy look at your querry and change in that querry the name fields to be the new name as opposed to the old ones. What you posted here refer to the querry name but we don't have the actual querry which should be a SELECT statment or INSERT INTO or UPDATE ... or whatever if you don't know how simply post the querry here and I can help you with it.
gowflow
0
 

Author Comment

by:Golfer219
ID: 38732640
Thanks for making me realize what the issue was gowflow!

I forgot that when you make a change to a table or query in Access, you need to open the query once to show you the results before trying to run the code.  Once I opened the query, closed it and exited out of Access, everything worked.

Thanks for your help!
0
 
LVL 29

Expert Comment

by:gowflow
ID: 38732992
Glad I could help you. Meantime have a Happy new year 2013 and all the best for you.
gowflow
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now