views:

100

answers:

4

What I am trying to do is make a form in Access and with out having to cut and paste over and over again have it ascend by rank, the problem with this is that lower ranks have letters closer to one if I have a list like this

Cpl 4th rank
MSgt 8th rank but it is a higher rank then Cpl
1st lt is is like the 11th ranking etc..
yes the 1st lt will usually go first but how would make it so that it shows up like
1st Lt
MSgt
Cpl

and there are other ranks out there. is there a module that i can use for this or would some one have to program something in visual basics for the spread sheet or for access. It is in database format but if I have to export it and do it in excell I can do that too.

+1  A: 

The usual way to do this is to have a table of ranks and the rank sort order, you can use this to sort your table, the record source of your subform would be on the lines of:

SELECT Rank.Sort, MainTable.Rank FROM MainTable 
LEFT JOIN Rank ON MainTable.Rank=Rank.Rank

You need to include a number that says how the table is to be sorted.

Rank   Sort
1st Lt   1
MSgt     2
Cpl      3

A relational database, such as Access, only has an order if you give it one.

You probably have a table with a lot of people, I have called this MainTable in my example, then you should have a look-up table, let us call it Rank, and it should look like the table illustrated above. This means that you do not need two fields in the main table to say what the rank is and how it should be sorted, in addition, a look-up table means that each entry is the same, so you don't end up with, for example:

1st Lt
First Lt
1st Lieut

You might like to read Fundamentals of Relational Database Design

Remou
Can you Make more sense of this I am confuse, I made a table named rank, then i put the ranks in the order I want then I am confused for this.
daddycardona
So if IhadID Rank1 1st Lt2 GySgt3 SSgt where is the rank.sort that I pick
daddycardona
I have added more information.
Remou
That's an old article i.e. Access 2.0 and some Access-specific details are out of date e.g. the engine has had the ON DELETE SET NULL referential action since Jet 4.0 Access2000. Oldie but goodie, though :) Nice that by 'relational' it means actually means 'relational'!
onedaywhen
ON DELETE SET NULL is a Jet 4 feature not implemented in the UI of any version of Access I've noticed. I don't believe it should exist, though, as if you need it you implement it with a join table.
David-W-Fenton
@David W. Fenton: "I don't believe it should exist" -- I don't think NULLable columns should exist but apparently you or I don't get to choose these things ;)
onedaywhen
A: 

I really do not understand all of that can you please explain a little better like my comment I have already made a table called ranks what do you mean by sort order?

daddycardona
A: 

To put it another way, you need to do you ORDER BY statement on the field “Sort_order” field from your rank table and not by the name of the rank itself.

I would also recommend stepping that field in increments of 10 so if a new rank comes in you can put it in between 2 others without having to update the other records (ahhhh takes me back to my old VIC20 programming days with line numbers)

Kevin Ross
A: 

In your ranks table add a new field called “Sort_order”. The query would look something like this

SELECT tblPeople.Name, tblRanks.Rank_name, tblRanks.Sort_order FROM tblPeople INNER JOIN tblRanks ON tblPeople.Rank_ID = tblRanks.Rank_ID ORDER BY tblRanks.Sort_order DESC;

The table tblPeople contains the details of the people like name etc and the table tblRanks contains the names of the ranks along with a field telling the database what order to sort them in so Sergeant is above private

Kevin Ross
I’m new to all of this so would someone tell my why this post of mine got voted down? Should I have done it as a comment?
Kevin Ross