Solved

Make Table Query in Access 2003 VBA

Posted on 2011-02-17
3
572 Views
Last Modified: 2012-05-11
I am executing a make table paramater query in vba

using the following code

  Dim db As Database
        Dim qry As QueryDef
       
   
   
        'use current database
        Set db = CurrentDb()
   
        'execute query
        Set qry = db.QueryDefs("Create_DailyStoreSalesFromROW")
         
        'specify value of parameters
        qry.Parameters("StartDate") = strStartDate
        qry.Parameters("EndDate") = strEndDate
         
        qry.Execute


When an attempt is made to try and execute qry.execute

it says the table already exists

I there a way to force the make table query delete the table like it does when you double click on it in the query window?



0
Comment
Question by:johnnyg123
  • 2
3 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
the quick and dirty

add  >> on error resume next


Dim db As Database
        Dim qry As QueryDef
       
on error resume next  
   
        'use current database
        Set db = CurrentDb()
   
        'execute query
        Set qry = db.QueryDefs("Create_DailyStoreSalesFromROW")
         
        'specify value of parameters
        qry.Parameters("StartDate") = strStartDate
        qry.Parameters("EndDate") = strEndDate
         
        qry.Execute
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
or this

Dim db As Database
        Dim qry As QueryDef
       
   
        'use current database
        Set db = CurrentDb()
   

if dcount("*","msysobjects","[name]='nameOfTable'")>0 then
db.execute "drop table nameoftable"
end if

  'execute query
        Set qry = db.QueryDefs("Create_DailyStoreSalesFromROW")
         
        'specify value of parameters
        qry.Parameters("StartDate") = strStartDate
        qry.Parameters("EndDate") = strEndDate
         
        qry.Execute
0
 
LVL 14

Expert Comment

by:Don Thomson
Comment Utility
Try unchecking the Action queries box under Tools - Options Edit/Find
Other than that you could just delete the table first - then create it - With an on_error that basically ignores the error
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

771 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

10 Experts available now in Live!

Get 1:1 Help Now