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

Question on using Make Table query in Access

Posted on 2011-09-04
10
397 Views
Last Modified: 2012-05-12
I like to have one Make Table query in Access that will be use to create 3 local tables from linked tables

For example I have:
Linked table A,B and C
Now in my query  Make Table I want to create AA, BB and CC local tables if I run it. Also I want to suppress any warning that it will delete the existing local tables

Can someone give me an idea if it is possible?
0
Comment
Question by:Gerhardpet
10 Comments
 
LVL 3

Expert Comment

by:babesia
ID: 36482074
VBA Code is one way.

create a form with a button to run some vba code.

code :
check for local table.
If exists : Delete existing data from local table.

Run update query from Link table


Done.
0
 
LVL 3

Expert Comment

by:sofsol
ID: 36482156
I have a query that over-writes a table, and I run that query from inside a macro. Start with the macro action SetWarnings set to No, then run your query, then close wih the macro action SetWarnings again but now set to Yes. Note that in Access 2010 to see the SetWarnings action you need to click on "Show All Actions" at the top of the maro design window.

delme.png
0
 
LVL 30

Expert Comment

by:hnasr
ID: 36482370
A make table query creates only one table.
You need to run 3 make table queries.
Or run VBA code to run sql changing the select part to create the tables.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 9

Accepted Solution

by:
Armen Stein - Microsoft Access MVP since 2006 earned 500 total points
ID: 36485262
MakeTable queries are notoriously unreliable, because they can take liberties with the structure of the new tables.

Instead, create your local tables just once, with the desired structure.  Then use two queries instead of the single MakeTable query.

1.  Delete all rows from the local table.  "Delete * from MyLocalTable"
2.  Insert the desired data into the local table using an Append query.

Warning messages can be suppressed using DoCmd.SetWarnings = False.  Turn it back on after your queries run.

Hope this helps,
Armen
0
 
LVL 1

Author Comment

by:Gerhardpet
ID: 36485396
Where is the DoCmd.SetWarnings = False setting in a query?

Sorry I'm a novice in Access
0
 
LVL 9
ID: 36485619
It isn't in the query, it's a command you can run in VBA or a macro.  It's documented in Help.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36485714
Docmd.sertwarnings will only suppress the message about running the Make table query.
You can avoid the "existing table" alert by any number of techniques.
If it were me, I would simple tell the code to delete the table if it exists.

Create a form
Drop a button on the form
On the OnClick event of the button, use code like this:

'------------------------------------------
    If DCount("Name", "msysobjects", "name='AA'" & " and type=" & 1) = 1 Then
        DoCmd.DeleteObject acTable, "AA"
    End If
    CurrentDb.Execute "SELECT A.* INTO AA FROM A;", dbFailOnError
   
    If DCount("Name", "msysobjects", "name='BB'" & " and type=" & 1) = 1 Then
        DoCmd.DeleteObject acTable, "BB"
    End If
    CurrentDb.Execute "SELECT B.* INTO BB FROM B;", dbFailOnError
   
    If DCount("Name", "msysobjects", "name='CC'" & " and type=" & 1) = 1 Then
        DoCmd.DeleteObject acTable, "CC"
    End If
    CurrentDb.Execute "SELECT C.* INTO CC FROM C;", dbFailOnError
   
    'Optional, Visual Confirmation
    'MsgBox "Done"

    'Optional, refreh the Database Window/Navigation Pane
    'RefreshDatabaseWindow
'-----------------------------------


Sample attached for fun

;-)

JeffCoachman
Database28.mdb
0
 
LVL 9
ID: 36485894
Hi Jeff, my point was not to delete or recreate the table object at all, just empty and refill the rows in a persistent table.  We're  discussing two different approaches here.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36485997
ArmenStein,

<We're  discussing two different approaches here.>
Ah, yes, ...

Sorry for the misunderstanding, ...

As I read my post, I should have made it clear that I was in no way saying that any other approach was invalid, or that my post was superior.

As always there is always more than one way of doing something, so it is best to know a few different approaches...
;-)

Jeff
0
 
LVL 10

Expert Comment

by:Luke Chung
ID: 36489697
I agree with Armen that MakeTable queries are dangerous to use. Far better to use a template table approach and use a DELETE query followed by the INSERT query.

I'm stunned I haven't written anything about this. Could have sworn I did in the past. Here's my paper on Microsoft Access Query Tips and Techniques (SQL and VBA) which should give you a solid overview of what you can do with Microsoft queries interactively and programmatically.

Our Microsoft Access Query Help Center offers even more query related resources.

Hope this helps.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 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