Beginner's question please. I have a form bound to tblMyTable. A numeric field is myNumber. For each new record (datasheet view), I want the text box control for that field to increment to the next number higher than the highest number entered so far (which is not necessarily the latest number). So in the Default Value property, I put:
=DMax(Nz("myNumber",0),"tblMyTable")+1
Doesn't seem to work. Let's say I have a bunch of records with myNum values progressing from 1-7 and an additional record - entered earlier - with myNumber=23. In the VBA immediate window, ?DMax(Nz("myNumber",0),"tblMyTable") gives 7. Why not 23?
There's an additional problem in that a new record appears in datasheet view before the current one is completely filled out. The new record has the (incorrect) entry for myNumber already there, even though I haven't tabbed to it yet. Even if the first problem were not occurring, it would still be incorrect (I presume), since the current record hasn't been entered in the table yet. (The data are transferred to the table from the form when you move to a new record, right?)
So general question: what is proper way to increment a bound numerical controller with a next highest number that has never been used at the point of new record creation, even if there is discontinuity in the existing sequence? (I'm aware of autonumber, but don't want to use it. I want user to be able to override the default value.)
Using Access 2010 under Win7x64. Many thanks, -Ron