[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Access 2007 VBA code for Make Table Query

Posted on 2009-12-21
2
Medium Priority
?
1,081 Views
Last Modified: 2013-11-27
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






0
Comment
Question by:pfmurray
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 26097829

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



0
 

Author Comment

by:pfmurray
ID: 26103124
Capricorn1 - Thank you very much indeed! I got an error initially in Excel  regarding  "Dim db as database" but I already had code that defines it thus: Set MyDatabase = New ADODB.Connection.

Once I replaced "db" in your example with "MyDatabase" this worked.


 
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
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 …
Suggested Courses

830 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