Solved

Make Table Query in Access 2003 VBA

Posted on 2011-02-17
3
619 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
[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
  • 2
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 34916717
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34916741
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
ID: 34916751
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

695 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