Link to home
Start Free TrialLog in
Avatar of johnnyg123
johnnyg123Flag for United States of America

asked on

Make Table Query in Access 2003 VBA

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?



ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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