Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have found your site brilliant. What makes it good are the people that contribute to the site..."

Geography

Where in the world do Tek-Tips members come from?
Niebotel (Programmer)
26 Aug 12 9:53
I have a form on which data can added. Each records gets its own recordnumber which is made on moment of enetering data. (I cannot use the internal number because in backgrounf sometime records are added and deleted again)


If I look into the table I see that my field ID in this table starts numbering from 1 after some hundred records. I'm not sure but I think that somehow the recordcount give 0 on some unexpected moment.
Does anybodey see a mistake in the coding?

I use the code below to do so:

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Set con = CurrentProject.Connection
Set rst = New ADODB.Recordset

On Error GoTo Error_BeforeInsert
rst.Open "Ontvangsten", con, adOpenStatic, adLockPessimistic

If rst.RecordCount = 0 Then 'this is done for the situation the table is empty
Me!ID = 1
Else
rst.MoveLast
Forms![Ontvangsten]!Nummer = rst!ID + 1
End If
rst.Close
Helpful Member!  missinglinq (Programmer)
26 Aug 12 11:27
You have no way to know what the 'last record' is going to be. This kind of thing is normally done using the DMax() function against the ID field and then adding 1 to that maximum number.


The Missinglinq

Richmond, Virginia

The Devil's in the Details!

Niebotel (Programmer)
26 Aug 12 12:52
Thanks that works fine; is there a simpel query which let met (re) number all the records starting from 1?
I mean a query not with VBA?
vbajock (Programmer)
27 Aug 12 9:00
Create an Update Query using DMAX+1
Niebotel (Programmer)
27 Aug 12 9:03
Would love to, but I do not know how to work with the DMAX
Could you give an example?
dhookom (Programmer)
27 Aug 12 9:14
Is this the same issue as thread701-1691734: update query for numbering records? Can we assume your question(s) have been answered?

Duane
Hook'D on Access
MS Access MVP

Niebotel (Programmer)
27 Aug 12 9:19
Almost; I'm still interested in the solution with DMAX for the DCount is very inefficient; I'm working on table with some 1000 records situated on a sharepoint. DCOUNT solution took me 10 minutes to run, although it workde fine!
vbajock (Programmer)
27 Aug 12 9:24
If you don't know how to work with the DMAX function, press the f1 button.
Helpful Member!(2)  dhookom (Programmer)
27 Aug 12 10:06
Niebotel (Programmer)
27 Aug 12 10:15
Great guys!

Gr. Willem

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close