Total Records display incorrect total

GregSmith

Registered User.
Local time
Today, 14:51
Joined
Feb 22, 2002
Messages
126
I have a table that I have entered in information from the form but decided not to save it. It still counts up the record number but the ID is not the same.

IE: viewing the data in my table displays ID's 1-259. But I may be missing ID's 20-25, 30, 240-245 etc.

So when you use the dcount command, it does not match up with the real total record count.

Any ideas on how to sync them back?
 
What I am trying to say is that my ID field does not match up with the record field on my form...
 
Assuming that your ID field is an AutoNumber, this is normal behavior. Whenever you start a new record, and then abandon it without saving, the AutoNumber value that was displayed in the abandoned record is discarded.

If your application requires that the actual record count always matches the last ID number used, you could change the ID field from AutoNumber to Number/Long, and manually set its value via the form's code module. For instance, you could put this code into the form's BeforeInsert event procedure:

txtID = DMax("ID", "MyTable") + 1

This event will fire only when you begin a new record. If you abandon the record without saving, the DMax function will return the same value for the next new record.

You'll still have the problem of what to do about your existing data (and even using the DMax function you'll still get out of synch if you delete any records other than the last one). You can "fix" existing data by setting up a macro which does the following:

1. run a maketable query to create a temp table with the same structure and contents as the original.
2. delete all records from the original table.
3. run an append query to rebuild the original table from the temp table. All fields will be copied in as is, except for the ID field. If you're simply cleaning up the existing data, the ID field values will be assigned automatically (since it's an AutoNumber field). If you're using the DMax approach on the form, you'll have to use the same approach in the append query (if that doesn't work, an alternative is a VBA function using DAO/ADO to accomplish the same thing one record at a time).

After you compact a database, the next AutoNumber value for each table will be one more than the last existing value, but that won't help you if you've deleted any records other than the last one(s).
 
You both are way above me, so feel free to throw this away if it is off base, but...
if <AutoNumber> is saving any records that you don't want in your table, and this is messing up the count sync, delete the blank records.
Then make a copy of the entire table, naming it almost the same as the original. Delete the original table, and rename the copied table exactly as the original was named.
This should reset your <AutoNumber> field and resync the records. ...grb
 

Users who are viewing this thread

Back
Top Bottom