Solved

Excel Access VB - Database pull

Posted on 2012-12-30
5
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 30

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 30

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 30

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

719 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