Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort 1

Status
Not open for further replies.

jass1220

Programmer
May 20, 2003
88
AE
am connecting VB with access ..

i have a trainees form , when i click on New it should gives me the new ID automatically by adding one to the last ID ... now .. what am using is this code:

//////////////////////
rsTrainee.MoveLast
intID = rsTrainee.Fields("trainee_id").Value
rsTrainee.AddNew
Me.txtTraineeID.Text = intID + 1
////////////////////

the problems is that access sorts the IDs Ascending in this way:
1
10
11
12
2
3
4
5
6
7
8
9
..
so the last value will be 9 not 12 !! and the new id will be 10 not 13 ... so what can i do in this case??
 
I'm guessing you have the ID column defined as Text - change it to a numeric and the problem will disappear.


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
but i need to keep it as text becouse it makes error in the program if it is not text .. is there any other solution ..
 
Okay,

so set the width of the primary ket field to something like 10 then format the values enetered as you insert them using Format (rsTrainee "Trainee_id"), "000000") or similar.

You either need to turn the values into genuine numbers or add leading zeroes, find and fix the cause of the errors caused by changing from text to numeric.

If none of the above is feasible then I would suggest storing a value elsewhere in the database that contains the next Id number.


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Glad to be of help.

Thanks for the star!


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top