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
Solved

Make Table Query in Access 2003 VBA

Posted on 2011-02-17
3
608 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 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
File.Search issue 8 33
Dot leaders between two labels in report 10 33
IIF in access query 19 25
Help formatting a report 3 17
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

828 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