Connecting Tech Pros Worldwide Help | Site Map

AutoNumber and Filling a text box display with autonumber

  #1  
Old June 16th, 2006, 01:45 AM
jason.teen@gmail.com
Guest
 
Posts: n/a
Hi,

Curerntly I have designed my table in MS Access with a column of
"RuleID"
and is set to (autonumber)

tblRule:
RuleID | Name
-------------------------------
1 | One
2 | Two
(autonumber)

I have then now created a form with a simple text boxes and an insert
button
1) How can I put that "next auto number" into a textbox in a form so
that it can be displayed for the user's purposes? I cannot find it in
any of the textbox properties. I even tried using SQL queries to maybe
do a "select max(ruleID) from tblRule" to fill it. or "Select
count(ruleID) from tblRule, but those ideas dont work

frmInsertRule:
RuleID: [textbox] <--- I want this to be auto filled with the number
"3" here from autonumber
Name: [textbox]


2) I have noticed that while testing my form I have created many many
rules.. and I insert them and then delete them except for the first two
rows.. but the autonumber just contines without taking into
consideration the next increment in the rule ID table.

ie. I get this:
tblRule:
RuleID | Name
-------------------------------
1 | One
2 | Two
265 | Three

instead of

tblRule:
RuleID | Name
-------------------------------
1 | One
2 | Two
3 | Three.

  #2  
Old June 16th, 2006, 02:45 AM
w_a_n_n_a_l_l_ -@-_s_b_c_g_l_o_b_a_l._n_e_t
Guest
 
Posts: n/a

re: AutoNumber and Filling a text box display with autonumber


1. If you put a control on a form and bind that control (through
controlsource property) to the autonumber field, you will see the new
autonumber value the moment someone types the first character into a new
record. this assumes that you are using a bound form and bound controls for
adding a new record.

2. The behavior you describe is by design. the autonumber type does not go
back and re-use a number for any reason. If you add 100 records to a brand
new empty table, the autonumber field numbers will be from 1 to 100. If you
delete the row that has id=50, that number is gone. The next new record
gets id 101.

3. There is no really good reason to show users an autonumber field. Its
main use is as a primary key, purely to identify "the row with id #nnnn".
Whether there are gaps in the numbers or not is immaterial to that use of
the field.

If you want to guarantee some sequential numbering for some other purpose,
you can do so in code. You can even re-use numbers in the number field you
create for that purpose, though it is rare to have a really good reason to
do that.
Closed Thread