We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Using "Select * INTO"  and original table field captions carryover.

DieszelDawg
DieszelDawg asked
on
Medium Priority
367 Views
Last Modified: 2010-05-18
Experts,
    Should be an easy one. When you use a "SELECT * INTO ..." statement to create a new table, why dont the original table field captions carryover to the new table (they differ from the field names due to spaces making the forms more understandable)??

Dieszel
Comment
Watch Question

Commented:
I believe that the answer lies in the fact that SQL is the standardized way of manipulating data, and while it can create a table, the commands are quite limited in standard SQL.  The caption field property is an MS Access property, not "standard."
I think the answer lies in copying and pasting the Access object, rather than moving the data via SQL.  The approach is probably to be found in a VBA reference somewhere.  I will try and find an actual code snippet for you.

HTH,

Tim
Database Developer
CERTIFIED EXPERT
Commented:
Yeah it's pretty standard type code to loop through and set the properties you want.

For example to just view one

Debug.Print currentdb.TableDefs("TableName").Fields("FieldName").Properties("Caption")

You could set them the same way
Loop through the fields of the old table - setting the captions in the newly created one.

The only thing to be aware of is that the Caption property doesn't exist when the field has no caption - so you'll be creating the property for each field.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Commented:
Okay, I found something that works in VBA.  The standard approach is to use the DoCmd.CopyObject method.  The sample below copies the Employees table in Northwind, making a backup copy (in the same database) as BUEmployees.  It could also make a copy of the table in another database by specifying the other database name as the first parameter (see the help for CopyObject from any code module).
I used two procedures, one calling the other, and passing it the table name to be copied:
Public Sub CopyTable(strTableName As String)
DoCmd.CopyObject , "BU" & strTableName, acTable, strTableName

End Sub

Public Sub TEST()
Dim strTableName As String
strTableName = "Employees"
Call CopyTable(strTableName)

End Sub

HTH,

Tim

Commented:
P.S.
    The backup copy of the table which is created using the DoCmd.CopyObject method carries over ALL properties, including the caption property.

Tim

Author

Commented:
Tim and LPurvis,
    Makes sense ... I forgot ny own rule about viewing everything I do in Access as VB and SQL, not just one or the other.

Author

Commented:
Tim and LPurvis,
     Im doubling and splitting the points.... When I asked the question I should have the the WHERE claus, which looking back is why I didnt go the COPYOBJECT route.... I didnt want the whole table recreated, just certain catagories with possible appends of other catagories later. LPurvis, I'll give it a try your way... Thanks both.

Dieszel
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.