Solved

Excel Access VB - Database pull

Posted on 2012-12-30
5
263 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using vb script 5 52
Converting time 4 44
Excel 2013 - default cell reference has changed from relative to absolute 7 23
Find the duplicates in 32 23
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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 create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

726 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