OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How To Reorder Fields in a Table?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
MichaelCrawford
General User
General User


Joined: 23 Jun 2008
Posts: 8
Location: Silicon Valley

PostPosted: Mon Jun 23, 2008 9:04 am    Post subject: How To Reorder Fields in a Table? Reply with quote

I have an address book in a database. But when I view its table, the fields (columns) are arranged left-to-right in the order I created them. This turns out to be somewhat random, and not at all what you'd want for data entry into the table.

For example I have an AutoField called Customer ID. It's in the middle somewhere. I'd like to make it the leftmost field.

One would think that I could drag the column header to a new position, and I get UI feedback as if this would work, but it doesn't.

Is there a way to rearrange my fields? Thanks!
_________________
Please download my Creative Commons piano compositions.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
QuazzieEvil
Super User
Super User


Joined: 17 Jan 2007
Posts: 599
Location: Houston, TX

PostPosted: Mon Jun 23, 2008 9:15 am    Post subject: Reply with quote

The only ways I can think of are: 1) create a view or query, and add the columns in the order you want and 2) create a form with a Table grid, and add columns to the table grid in the order you want.
Back to top
View user's profile Send private message Visit poster's website
MichaelCrawford
General User
General User


Joined: 23 Jun 2008
Posts: 8
Location: Silicon Valley

PostPosted: Mon Jun 23, 2008 9:25 am    Post subject: Reply with quote

Hey, thanks for your help.

For some reason I couldn't create a view at all. The Help says Views can only be created if the back end allows them - my database is one created by OOo itself, not an ODBC or what have you.

But creating a form with a table grid in it worked. It turned out that I still added a field in the wrong order, but the form wizard has a button that raises or lowers a field relative to the others. Works great!
_________________
Please download my Creative Commons piano compositions.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
QuazzieEvil
Super User
Super User


Joined: 17 Jan 2007
Posts: 599
Location: Houston, TX

PostPosted: Mon Jun 23, 2008 9:30 am    Post subject: Reply with quote

when you are in design mode, you can move columns in a tablegrid by dragging them about.
Back to top
View user's profile Send private message Visit poster's website
VenturSum
General User
General User


Joined: 28 Jun 2008
Posts: 10
Location: Annapolis, MD, USA

PostPosted: Sun Jun 29, 2008 4:59 pm    Post subject: Reply with quote

QuazzieEvil,

It seems that I can not move columns about. In MS Access I can easily move them about. But in Open Office I can't. Are there settings that allow your intallation of OpenOffice to have this feature??

Than you,

John in Annapolis, MD
Back to top
View user's profile Send private message
QuazzieEvil
Super User
Super User


Joined: 17 Jan 2007
Posts: 599
Location: Houston, TX

PostPosted: Mon Jun 30, 2008 8:48 am    Post subject: Reply with quote

are you refering to the table or the table control? in the table control, the form must be in design mode.
_________________
Free Docs @ http://www.baseprogramming.com/resources.html
Book @ lulu.com http://www.lulu.com/content/2455551
Back to top
View user's profile Send private message Visit poster's website
Qabyss
Newbie
Newbie


Joined: 01 Dec 2010
Posts: 1

PostPosted: Wed Dec 01, 2010 2:08 pm    Post subject: Copy and Paste the existing table Reply with quote

From the database management console, right-click on the table who's items you want to re-order and copy it.. Then paste it, when you do this, you will create a duplicate table and during the process of creating the duplicate you have the opportunity to re-order your items! Smile

~Q
Back to top
View user's profile Send private message
MSPhobe
Super User
Super User


Joined: 29 Sep 2005
Posts: 529
Location: England

PostPosted: Sat Dec 11, 2010 12:42 pm    Post subject: Reply with quote

I would advise against the previous post as an "answer" in most cases.

Because....

It isn't a good idea to work directly with tables, on a day-to-day basis.

That "bad news" is minor, given the Good News that it is easy to create a form for interacting with the data in your table. The form can even look like the display you get when you work directly with the table. ("Datasheet" format, if memory serves).

AND: You can re-order the columns in the FORM to your heart's content.

===
I have to enter data from two different brokerage accounts into a single database in my own computer. The two firms present the data in different orders. No problem... I have two forms for entering data into my one table of stock market purchases and sales. One form, with the fields in one order, for entering the data presented to me by the first firm, and a second form, fields in a different order, for entering the data presented to me by the second firm.

Each form "copies" the field sequence of the source document I am harvesting data from, so the harvest process is simple... and it is therefor harder to make mistakes.

===
The order of the fields IN THE UNDERLYING TABLE doesn't matter... does it? (Apart from the field which is the primary key for the table having(?) to be first(?))
Back to top
View user's profile Send private message
clearcomms
Newbie
Newbie


Joined: 14 Dec 2010
Posts: 3

PostPosted: Tue Dec 14, 2010 7:58 am    Post subject: Reply with quote

My problem is simple and I'm sure far from unusual. I have an existing database, imported from an MS Access database that had been running for some years. It is membership records. Now we need to add two new columns for 2011 Easy.

I add them in Design View. The two columns are at the bottom of the list. I drag them to the place in the list where I wish them to appear (logically, right after 2010!) and save the database.

Trouble is when I open the database proper, the columns are still over on the right hand side, even though if I go to Design View they are where they should be, in the middle.

Where am I going wrong, and why can't I just drag the columns in the database, as I can in some well-known databases?
Back to top
View user's profile Send private message
MSPhobe
Super User
Super User


Joined: 29 Sep 2005
Posts: 529
Location: England

PostPosted: Tue Dec 14, 2010 10:04 am    Post subject: Reply with quote

I think you may be confusing "database" and "table".

And I think my previous post, the post before the one before this one, gives you a solution to what you want... What do others who know about tables AND forms think?

The following may be useful...

http://sheepdogguides.com/fdb/fdb1intro.htm
Back to top
View user's profile Send private message
Sliderule
Super User
Super User


Joined: 29 May 2004
Posts: 2474
Location: 3rd Rock From The Sun

PostPosted: Tue Dec 14, 2010 10:08 am    Post subject: Reply with quote

clearcomms:

You did NOT say, but, I will assume the database engine you are using is HSQL . . . you can confirm this by looking at the bottom, on the Status Bar line, after opening your OpenOffice Base file ( *.odb ).

If it says . . . Embedded database and HSQL database engine, the following instructions apply. I really do know what you meant when you said:

clearcomms wrote:
I have an existing database, imported from an MS Access database that had been running for some years.


"Import a database" . . . are you using HSQL as your database engine, OR, are you connected to your Access database via a driver and writing / reading your Access database?

According to HSQL database documentation found at:

http://www.hsqldb.org/doc/guide/ch09.html#alter_table-section

HSQL Documentation: http://www.hsqldb.org/doc/guide/ch09.html#alter_table-section wrote:

ALTER TABLE

ALTER TABLE <tablename> ADD [COLUMN] <columnname> Datatype
[(columnSize[,precision])] [{DEFAULT <defaultValue> |
GENERATED BY DEFAULT AS IDENTITY (START WITH <n>[, INCREMENT BY <m>])}] |
[[NOT] NULL] [IDENTITY] [PRIMARY KEY]
[BEFORE <existingcolumn>];

Adds the column to the end of the column list. The optional BEFORE <existingcolumn> can be used to specify the name of an existing column so that the new column is inserted in a position just before the <existingcolumn>.


The above command is issued from the Menu: Tools -> SQL... in the Command to execute box, enter the SQL code below, and, press Execute button.

For example, assume your table name is "MyTable" and you want to ADD a column by the name of "2011" and you want to ADD the column before a pre-defined column name of "MyNextColumn" . . . you would enter ( change the table and field names to your needs ) :

Code:
Alter Table "MyTable" Add Column "2011" VARCHAR(50) Before "MyNextColumn"


Of course, you will have to modify the above to the REAL names in your database / table. Also, MOST IMPORTANT, the names ( table and column names ) must be entered EXACTLY as you have defined them in your database . . . including CASE ( UPPER / Mixed / lower ). For example, "MyTable" is not the same as "mytable" nor "MYTABLE". Smile

After pressing the Close button, you should:
  1. From the Menu: View -> Refresh Tables
  2. Go back to your Table in Edit mode ( GUI - Graphic User Interface ) and review the table to make sure everything is how you want it defined INCLUDING the field type. For example, if you did NOT want to define it as a VARCHAR(50) field but something else ( for example decimal ) . . . you can change it here.
I hope this helps, please be sure to let me / us know.

Sliderule
Back to top
View user's profile Send private message
clearcomms
Newbie
Newbie


Joined: 14 Dec 2010
Posts: 3

PostPosted: Tue Dec 14, 2010 10:18 am    Post subject: Reply with quote

I really do appreciate these two very quick and helpful replies.

I shall get onto this in the morning, and I'm sure i can make one of them work for the (non-expert) who is actually running the Membership database.

And to clarify things, we are NOT running the Access database - I extracted the data and then imported it into a new OoDb database, so we are running the HSQL engine.

Thanks again, guys!
Back to top
View user's profile Send private message
clearcomms
Newbie
Newbie


Joined: 14 Dec 2010
Posts: 3

PostPosted: Wed Dec 15, 2010 3:49 am    Post subject: Reply with quote

Sliderule's solution works perfectly, and is simple - who could ask for more.

I've tested it successfully on a "spare" database, so we'll be able to update our Membership Records easily.

And for me at least this is by far the best way to handle it - simpler than doing a form.

Many thanks for your help
Back to top
View user's profile Send private message
dacm
Super User
Super User


Joined: 07 Jan 2010
Posts: 734

PostPosted: Tue Dec 21, 2010 7:59 pm    Post subject: Reply with quote

Thank you sliderule! I'm still experimenting with the SQL method, but this column reordering is also possible using the Base GUI for the most part. I made a quick tutorial here but it's specific to the "embedded database" using the "HSQL database engine."

The GUI method can be done with a "file/server" mode database as well, but there's no 'Rename' Table function available in that case, so you'll have to use 'Copy table' a second time to change the name. And these external databases (file/server mode) require the external database workaround to re-establish the Auto-Incrementing primary key feature. So I may do a "file/server" (external database) version of the tutorial, but I'll have to play with the SQL method to see which seems easier.
_________________
Soli Deo gloria
Tutorial: avoiding data loss with Base + Migrating 'Embedded databases'
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group