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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

field with self generating value

Status
Not open for further replies.

kfenner

Technical User
Apr 6, 2003
52
US
<grumble> I feel so stupid here. How do you get a field in a form to update it's number value by one each time a new record is inserted. Basically I have a field which is &quot;IdNo&quot; and I want it to go up by one each time you insert new record without having to input the number yourself, thus preventing duplicating numbers.
 
kfenner,

There are a couple of ways to do this, but I'd probably:

1. Bind a field object to the underlying field value and then set its Visible property to false.

2. Add code to the action event of either a record object (preferred) or the form:

Code:
if eventInfo.id() = dataInsertRecord then
   fldCounter.Value = fldCounter.Value + 1
endIf

Mind you, this assumes a lot of thing, including:

-- You're already in Edit mode.
-- You're not storing the insert count in the table that you're adding the record to
-- You're going to add error-detaction and handling
-- And a host of other things that aren't occurring to me off the top of my head. :)

Alternatively, you could just call the nRecords() method of a UIObject bound to the table in question. In fact, if you define a calculated field to do that, it will update itself whenever the target table gets updated.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top