Question : Access 2007 VBA code for Make Table Query

Hi Experts

I have an Access 2007 database which includes some  pass-through queries to a Great Plains database. The data in these queries is not updated very frequently however because of the way I'm using the db (Excel forms based interrogation of the Access db) the response times when these queries are invoked makes the Excel form user experience very slow. The GP databases are in USA and I'm in London.

So - what I want to do is to make a VBA routine in Access (which I can fire up from the Excel interface) which effectively makes a static table from the pass through. I have tested the db using this technique and the Excel forms run way faster. I don't need to make the static table from the actual pass-through query, I have a query on the query which allows me to Trim etc.

This is what I'd like to automate

1) Select the Query "CustomersTrimmed" (which is a query based on a pass through query called "Customers__GP")

2) Make a table from "CustomersTrimmed" called "Customers" - this table already exists and I'd prefer it to be recreated each time the VBA runs (unless the advice is to the contrary). The Excel forms will point to this table for Customer data rather than the pass-through query.

3) Suppress all warning messages so the user can can just click on the Excel form to update the table

I'm comfortable with Excel VBA but I've never touched Access VBA so I'm hoping someone can take me step by step through this.


I'm sorry if this is answered elsewhere but on searching today I haven't found anything I recognised.

Cheers

Peter






Answer : Access 2007 VBA code for Make Table Query


place this codes in a module in Excel

sub createTable()
on error resume next
Dim db As Database, strSQL As String, dbPath As String
dbpath="C:\myFolder\myDb.accdb"

set db=opendatabase (dbPath,True)

db.execute "drop table customers"   'delete the table customers

strSql="select CustomersTrimmed.* into Customers from CustomersTrimmed"

db.execute strSql

db.close

end sub



Random Solutions  
 
programming4us programming4us